简体   繁体   中英

execute command on ec2 after ssh login using bash script

This code opens up three windows on my system and logs in into three different ec2 instances.

(xterm -geometry 70x70-0-0 -e ssh -i key1 ec2-user@52.x.x.x;) & 
(xterm -geometry 70x70+485-200 -e ssh -i key1 ec2-user@52.x.x.x;) &
(xterm -geometry 70x70+0-0 -e ssh -i key1 ec2-user@52.x.x.x;) 

However, I want to login into these three instances and execute respective commands in them. Something like:

(xterm -geometry 70x70-0-0 -e ssh -i key1 ec2-user@52.x.x.x; **run python file on this instance**) & 
(xterm -geometry 70x70+485-200 -e ssh -i key1 ec2-user@52.x.x.x; **run node file on this instance**) &
(xterm -geometry 70x70+0-0 -e ssh -i key1 ec2-user@52.x.x.x; **run R file on this instance**)

Do this:

(xterm -geometry 70x70-0-0 -e ssh -i key1 ec2-user@52.x.x.x -t "script.py ; bash";) &

the -t option make a tty and with bash after script.py you would get an interactive bash to continue commanding.

The main thing to change is getting rid of the semicolon before the "** run" (as well as using a real command). Something like

(xterm -geometry 70x70-0-0 -e ssh -i key1 ec2-user@52.xxx ** run python file on this instance ** ) &
(xterm -geometry 70x70+485-200 -e ssh -i key1 ec2-user@52.xxx ** run node file on this instance ** ) &
(xterm -geometry 70x70+0-0 -e ssh -i key1 ec2-user@52.xxx * **run R file on this instance*** ) &

After the options (such as -i ) and login information, ssh accepts a command and arguments.

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