Linux 简单期望脚本
我正在尝试运行一个简单的expect脚本,在远程主机中创建一个文件,下面是脚本: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
#!/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密钥管理很好,我没有想到这一点!这是最简单的解决方案,谢谢!