问题描述
我在本地计算机上有一个脚本,可以帮助我连接到我的 ec2 .但是,它不会运行指定的脚本文件.
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:
awsconnect.sh:
ssh -i ".pemfile" ubuntu@"ec2-instance"
./data.sh
data.sh
是我在 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
如果我从 aws-ec2 命令行运行data.sh
文件,则该文件运行良好.但是,它不是从我的脚本文件运行的.有什么问题吗?
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?
推荐答案
您可以ssh进入计算机吗?如果是这样,那么您只需要确保脚本的所有权和权限是正确的即可.然后您可以:
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"
但是,如果脚本中的内容需要root访问权限,则需要权限.
However, if things in your script need root access, then you would need permissions.
如@ error2007s所述,我忘记在命令中指定身份文件.我已经编辑了命令,因此将其放在awsconnect.sh
中,它应该可以正常工作.
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.
这篇关于如何从本地计算机上的脚本在aws-ec2上运行脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!