简体   繁体   English

如何制作连接到服务器并在“屏幕”内执行命令的 shell 脚本?

[英]How to make a shell script that connects to a server and executes commands inside `screens`?

On Linux. I need to write a file containing a script.在 Linux。我需要编写一个包含脚本的文件。
My script should connect to a server, create a screen and execute a command.我的脚本应该连接到服务器、创建screen并执行命令。 Several times automatically.多次自动。

Pseudocode of the script:脚本的伪代码:

ssh machine1
cd project_folder
screen -S screenA
python run.py -x
exit
screen -S screenB
python run.py -y
exit
exit

ssh machine2
cd project_folder
screen -S screenA
python run.py -z
exit
screen -S screenB
python run.py -t
exit
exit

ATM I can just connect and run each command manually. ATM 我可以手动连接并运行每个命令。

Yes, thanks https://stackoverflow.com/users/9215267/siddharth-dushantha是的,谢谢https://stackoverflow.com/users/9215267/siddharth-dushantha
And for the part of screen the code is对于screen的一部分,代码是

screen -dmS screen0
screen -ls
screen -r screen0 -p 0 -X stuff "the_command1^M"
screen -r screen0 -p 0 -X stuff "the_command2^M"

where ^M types enter at the end of the line.其中^M类型在行尾enter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM