问题
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