我想在服务器列表上运行并在使用时远程运行脚本screen
。
手动地,我会这样做:
screen -RD
./run_script
并手动远程我会这样做:
ssh root@server "screen -RD && ./run_script"
但实际情况是它screen -RD
正在运行,只有当我输入时exit
它才开始运行脚本。
那么如何实现screen -RD
远程运行,然后在首屏终端内发出命令呢?
编辑#1:
[root@edge14 ~]# screen -r -X /nfs/ops/component/edge/scripts/move_stuck_aggfiles_to_hadoop.sh && screen -RD
No screen session found.
[root@edge14 ~]#
答案1
你用-X
开关。从手册页:
-X Send the specified command to a running screen session. You can use the -d or -r option to tell screen to look only for attached or detached screen sessions. Note that this command doesn't work if the session is password protected.
将此与实际看到屏幕结合起来:
ssh root@server "screen -dr -X ./run_script && screen -RD"
(但是你真的不应允许 ssh 以 root 身份登录,从安全角度来看这是非常糟糕的做法。)