views:

757

answers:

2

I would like to execute a ssh command and pipe the output to a file.

In general I would do:

ssh user@ip "command" >> /myfile

the problem is that ssh close the connection once the command is executed, however - my command sends the output to the ssh channel via another programm in the background, therefore I am not receiving the output.

How can I treat ssh to leave my shell open?

cheers

sven

A: 

My understanding is that command starts some background process that perhaps will write some output to the terminal later. If command terminates before that the ssh session will be terminated and there will be no terminal for the background program to write to.

One simple and naive solution is to just sleep long enough

ssh user@ip "command; sleep 30m" >> /myfile

A better solution than sleep would be to wait for the background process(es) to finish in some more intelligent way, but that is impossible to say without further details.

hlovdal
thanks a lot. but the remote system is a closed system with no access to a real shell (think of a cisco ssh shell), so no custom commands are allowed. To simplify what I need is I want to have the following command executed without closing the ssh channel once the execution finished (this must be done without chaning anything at the "command" itself, so no remote changing): ssh user@ip "command"
sven
A: 

Something more powerful than bash would be Python with Paramiko and PyExpect.

fuzzy lollipop