简体   繁体   English

使用bash脚本ssh登录后在ec2上执行命令

[英]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. 此代码在我的系统上打开三个窗口,并登录到三个不同的ec2实例。

(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. -t选项创建一个tty,并在script.py之后加上bash ,您将获得一个交互式bash以继续执行命令。

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-0-0 -e ssh -i key1 ec2-user@52.xxx **在此实例上运行python文件** ) &
(xterm -geometry 70x70+485-200 -e ssh -i key1 ec2-user@52.xxx ** run node file on this instance ** ) & (xterm -geometry 70x70+485-200 -e ssh -i key1 ec2-user@52.xxx **在此实例上运行节点文件** ) &
(xterm -geometry 70x70+0-0 -e ssh -i key1 ec2-user@52.xxx * **run R 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. 在选项(例如-i )和登录信息之后, ssh接受命令和参数。

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

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