运行 ssh 并立即执行命令 [英] Run ssh and immediately execute command
本文介绍了运行 ssh 并立即执行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在连接到 ssh 服务器后找到 UNIX 或 bash 命令来运行命令.例如:
I'm trying to find UNIX or bash command to run a command after connecting to an ssh server. For example:
ssh name@ip "tmux list-sessions"
上述代码有效,它列出了会话,但随后立即断开连接.将它放在服务器端的 sshrc 中可以工作,但我需要能够在客户端输入它.我希望能够运行一个命令,它登录,打开窗口,然后运行我设置的命令.我试过了
The above code works, it lists the sessions, but it then immediately disconnects. Putting it in the sshrc on the server side works, but I need to be able to type it in client side. I want to be able to run a command, it logs in, opens up the window, then runs the command I've set. Ive tried
[command] | ssh name@ip
ssh name@ip [command]
ssh name@ip "[command]"
ssh -t name@ip [command]
推荐答案
ssh -t 'command; bash -l'
将执行该命令,然后在它完成时启动一个登录 shell.例如:
will execute the command and then start up a login shell when it completes. For example:
ssh -t user@domain.com 'cd /some/path; bash -l'
这篇关于运行 ssh 并立即执行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文