![](/img/trans.png)
[英]User data bash script to start services in EC2 instance not executing
[英]bash script accessing ec2 instance
这个脚本需要一个IP,我们必须在远程服务器上运行的脚本或文件,我给了一个文件,其中我写了以下命令
touch /root/test
ls /root/test
这使文件,但不显示,它显示一个错误
tcgetattr:设备的不适当的ioctl
连接已关闭
我该如何解决?有什么建议吗?
#!/bin/bash
# The private key used to identify this machine
IDENTITY_KEY=/home/admnew.pem
syntax()
{
echo "Syntax: Ec2.sh server_ip scriptFile]"
echo "For example: ./Ec2.sh server_ip scriptFile"
exit 1
}
if [ $# -ne 2 ]
then
echo not enough arguments
syntax
fi
echo "Running script $2 on $1"
ssh -t -t -i $IDENTITY_KEY ec2-user@$1 sudo -i 'bash -s' < $2
exit
exit
echo "Done"
尝试:
ssh -t -t -i $IDENTITY_KEY ec2-user@$1 sudo -i 'bash -s' <<EOF
(
$(cat "$2")
)
EOF
例如,将脚本包装到()
,例如:
touch /root/test
ls /root/test
应该
(
touch /root/test
ls /root/test
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.