Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the PipedInputStream to stream to stdout? #19

Open
jeroenvandijk opened this issue Feb 19, 2013 · 2 comments
Open

How to use the PipedInputStream to stream to stdout? #19

jeroenvandijk opened this issue Feb 19, 2013 · 2 comments

Comments

@jeroenvandijk
Copy link

Sorry to bother you with a "support" question. Normal usage of this library works really great, thanks for that.

Now, I would like to stream ssh session output to stdout. I tried several variations of the below and I also tried examples I found on the web, but without luck.

(require '[clj-ssh.ssh :as s])
(require '[clj-ssh.cli :refer [ssh]])

(let [{shell :channel out-stream :out-stream} (ssh host :cmd "sleep 10; echo hi" :strict-host-key-checking :no :out :stream)]
(s/with-channel-connection shell (while (s/connected-channel? shell) (println "connected")) (println "nothing")))

Am I missing something?

@abailly
Copy link

abailly commented Dec 16, 2013

I have tried the following but it does not work: ssh exits after first line of input gets retrieved.

(defn stream-events
  "Connect to gerrit server and stream events to stdout"
  [host port]
  (let [agent (ssh-agent {:use-system-ssh-agent false})]
    (add-identity agent {:private-key-path "/home/user/.ssh/id_rsa"})
    (let [session (session agent host {:strict-host-key-checking :no
                                                       :port port})]
      (with-connection session
        (let [result (ssh session {:cmd "gerrit stream-events"
                                   :out :stream})
              reader (io/reader (:out-stream result))]
          (map #'println (line-seq reader)))))))

I also would like to be able to stream the output from the remote shell, here to simply propagate to stdout but later on to do more interesting things.

@mattford63
Copy link

mattford63 commented Jan 25, 2017

I did the above successfully with the following final line

(doall (map println (line-seq reader))))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants