简体   繁体   中英

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.
My script should connect to a server, create a screen and execute a command. 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.

Yes, thanks https://stackoverflow.com/users/9215267/siddharth-dushantha
And for the part of screen the code is

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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