期待与sshfs的翻译

时间:2017-01-15 05:02:34

标签: linux bash expect sshfs

无法设法解决这个问题

!/usr/bin/expect -f
set prompt ":|#|\\\$"
set HOST "192.168.0.40"
set USER "root"
set PASS "1234"
set PATH "/rpms"
spawn "sshfs" "$USER@$HOST:$PATH" "/backup"
expect "Are you sure you want to continue connecting (yes/no)?"
send "yes\r"
expect "root@192.168.0.40's password:"
send "PASS\r"
exit

输出我得到:

spawn sshfs root@192.168.0.40:/rpms /backup
root@192.168.0.40's password: root@debian:/rpms#

并且目录未加载:

cd /backup
-bash: cd: /backup: Transport endpoint is not connected

如果我尝试手动sshfs root@192.168.0.40:/rpms /backup,那就可以了。

1 个答案:

答案 0 :(得分:0)

您将密码保存为变量PASS,但发送字符串PASS作为密码;传递变量扩展:

send "$PASS\r"