> /myfile" />
开发者

Script: SSH command execute and leave shell open, pipe output to file

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 ba开发者_Python百科ckground, therefore I am not receiving the output.

How can I treat ssh to leave my shell open?

cheers

sven


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜