linux 期望使用sshfs的解释器

368yc8dk  于 2023-01-20  发布在  Linux
关注(0)|答案(2)|浏览(116)

我无法解决这个问题

!/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,则工作正常

hfwmuf9z

hfwmuf9z1#

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

send "$PASS\r"
dbf7pr2w

dbf7pr2w2#

我也有同样的问题--sshfs似乎在其他任何地方都能工作,但在expect内部却不行。为什么会这样呢?expect提前终止了它还是怎么了?
我的expect代码:

spawn bash -c "sshfs  user@host.local:/ /home/user/remote-fs  -o ssh_command='ssh -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedKeyTypes=+ssh-rsa'"

此命令在bash中运行得非常好,但在expect中使用时会静默失败,并显示“transport endpoint not connected

相关问题