内联SSH命令


Answers:


27

如果要cd foo/bar && rm *.foobar在远程计算机上执行,只需执行

ssh foo@bar.com  'cd foo/bar && rm *.foobar'

看看man ssh...

ssh [-1246AaCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec] [-D
[bind_address:]port] [-e escape_char] [-F configfile]
[-i identity_file] [-L   [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-R
[bind_address:]port:host:hostport] [-S ctl_path] [-w tunnel:tunnel
[user@]hostname [command]

您想要的零件:

ssh [user@]hostname [command]

2
值得一提的是,您也可以使用此方法通过管道传输STDIN和STDOUT-就在前几天,我使用DD over ssh制作了远程计算机的高清图像。
crazy2be 2011年

9

样式1: ssh user@host 'embedded command'

样式2:ssh user@host " $(cat cmd.txt) "
cmd.txt是包含位于本地计算机上的远程命令的文件


7

是的 :

ssh foo@bar.com 'cd foo/bar && rm *.foobar '
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.