Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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 简单期望脚本_Linux_Ssh_Expect - Fatal编程技术网

Linux 简单期望脚本

Linux 简单期望脚本,linux,ssh,expect,Linux,Ssh,Expect,我正在尝试运行一个简单的expect脚本,在远程主机中创建一个文件,下面是脚本: #!/usr/bin/expect -f spawn ssh numeutente@11.11.11.111 expect "password: " send "psw\r" expect "$ " send "cd /var/www/localhost/htdocs/oss\r" send "touch file.txt\r" expect "$ " send "exit\r" 但当我检查时,没有file.tx

我正在尝试运行一个简单的expect脚本,在远程主机中创建一个文件,下面是脚本:

#!/usr/bin/expect -f
spawn ssh numeutente@11.11.11.111
expect "password: "
send "psw\r"
expect "$ "
send "cd /var/www/localhost/htdocs/oss\r"
send "touch file.txt\r"
expect "$ "
send "exit\r"

但当我检查时,没有file.txt。有什么问题吗?

该用户对该目录有写访问权限吗?如果我使用ssh手动登录并执行触摸,我就能够创建文件(我在脚本中使用我的用户)…所以我想是的,你为什么不使用
ssh呢numeutente@11.11.11.111touch/var/www/localhost/htdocs/oss/file.txt
?登录身份验证可以用ssh密钥管理很好,我没有想到这一点!这是最简单的解决方案,谢谢!