是否可以执行一个简单的内联样式 SSH 命令,例如:
ssh [email protected] { cd foo/bar && rm *.foobar }
答案1
如果你想cd foo/bar && rm *.foobar
在远程机器上执行,只需执行
ssh [email protected] '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
风格一:ssh user@host 'embedded command'
样式 2:ssh user@host " $(cat cmd.txt) "
cmd.txt 是包含位于本地计算机上的远程命令的文件
答案3
是的 :
ssh [email protected] 'cd foo/bar && rm *.foobar '