Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 访问ec2实例的bash脚本_Linux_Bash_Shell - Fatal编程技术网

Linux 访问ec2实例的bash脚本

Linux 访问ec2实例的bash脚本,linux,bash,shell,Linux,Bash,Shell,这个脚本需要一个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() {

这个脚本需要一个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"
#/bin/bash
#用于标识此计算机的私钥
IDENTITY_KEY=/home/admnew.pem
语法()
{
echo“语法:Ec2.sh服务器\u ip脚本文件]”
echo“例如:./Ec2.sh服务器_ip脚本文件”
出口1
}
如果[$#-ne 2]
然后
没有足够的论据
语法
fi
echo“在$1上运行脚本$2”
ssh-t-t-i$IDENTITY\u KEY ec2 user@$1 sudo-i'bash-s'<$2
出口
出口
回音“完成”
试试:

应该是

(
touch /root/test
ls  /root/test
)
@HassaanHashmi再次检查(使用
-x
)您是如何复制我的答案的。您是否在脚本中使用了double
no您说的是give(touch/root/test ls/root/test),但我在另一个文件中给出了它让我们看看这个脚本是如何工作的,例如:ec2.sh ip文件在这个文件中我给出了touch/root/test和ls/root/test以及文件正在创建的其他命令,但ls命令没有显示输出
touch /root/test
ls  /root/test
(
touch /root/test
ls  /root/test
)