![](/img/trans.png)
[英]How to execute a command on the remote at login with ssh, after .bashrc sourcing?
[英]tmux new-window ssh to remote host, then execute command and stay login
我在跳箱上使用tmux。 我正在尝试自动化某些常见情况。 我该怎么做?
我可以用ssh来做到这一点:
ssh -t root@2.158.0.10 "cd ~adarias/duncans/ServiceAgent/tests; bash -l -c 'mocha config_tests.js'; bash -l"
但不适用于tmux新窗口:
tmux new-window -t mosdev -d -n 'debug & test' 'ssh -T root@2.158.0.10 < .mosdev/scripts/test_config.sh; bash -l'
我将shell命令放在一个单独的文件中,因为我遇到了嵌套引号的问题,但无法弄清楚如何解决。
.mosdev /脚本/ test_config.sh:
#!/bin/bash
cd ~adarias/duncans/ServiceAgent/tests; bash -l -c 'mocha config_tests.js'; bash -l
到远程主机的ssh会话不会保持打开状态。 尽管新窗口打开了,但在跳转框的提示下我还是退回了。
那么,我在这里想念什么? 我如何使该会话保持打开状态?
我相信问题是使用ssh
命令。
从man ssh
的AUTHENTICATION
部分的末尾开始:
当远程计算机上的命令或外壳程序退出并且所有X11和TCP连接都已关闭时,会话终止。
因此,我认为您所看到的是ssh
的预期行为。
解决方法是,尝试使用tmux send-keys
告诉窗口登录,然后执行脚本:
tmux new-window -a -d -t mosdev -n debug-test
tmux send-keys -t mosdev:debug-test "ssh root@2.158.0.10" C-m
tmux send-keys -t mosdev:debug-test "cd ~adarias/duncans/ServiceAgent/tests; mocha config_tests.js" C-m
几个注意事项:
Cm
是返回键。 我注意到在回答时,这个问题已经两个月了。 你已经解决了吗? 如果是这样,您是怎么做到的?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.