无法设法解决这个问题
!/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
,那就可以了。
答案 0 :(得分:0)
您将密码保存为变量PASS
,但发送字符串PASS
作为密码;传递变量扩展:
send "$PASS\r"