How to run a script on your aws-ec2 from a script on your local machine?

梦想与她 提交于 2020-06-17 05:09:08

问题


I have a script on my local machine which helps me to connect to my ec2. But, it does not runs the script file specified.

awsconnect.sh:

ssh -i ".pemfile" ubuntu@"ec2-instance"


  ./data.sh

data.sh is my file on the aws-ec2.

data.sh:

 mkdir -p dumps/$(date +"%Y%m%d");
    mysqldump -h localhost -port=3306 -u root -proot abc | gzip > dumps/$(date +"%Y%m%d")/abc.sql.gz;
    logout

My data.sh file is running fine if i run it from aws-ec2 command line. But, it is not running from my script file. What is the problem?


回答1:


Are you able to ssh into the machine fine? If so, then you just need to make sure that ownership and permissions are ok for the script. Then you can:

ssh -i key.pem ubuntu@ec2-instance "bash /path/to/your/script/data.sh"

However, if things in your script need root access, then you would need permissions.

Edit: As @error2007s mentioned, I forgot to specify the identity file in my command. I've edited the command, so put that in awsconnect.sh and it should work fine.



来源:https://stackoverflow.com/questions/37751660/how-to-run-a-script-on-your-aws-ec2-from-a-script-on-your-local-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!