我有以下脚本:
#!/bin/bash
if [ `hostname` = 'EXAMPLE' ]
then
/usr/bin/expect << EOD
spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
spawn scp -rp host:~/errfiles/ /home/USERNAME/errfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
expect eof
EOD
echo 'Successful download'
fi
很不幸,它似乎无法工作,我收到了一个错误信息:
spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/
Enter passphrase for key '/home/USERNAME/.ssh/id_rsa': interact: spawn id exp0 not open
while executing
"interact"
我不知道它的含义和为什么它不起作用。然而,当我使用非嵌入式的Expect脚本编写上述代码时:
#!/usr/bin/expect
spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
spawn scp -rp host:~/errfiles/ /home/USERNAME/errfiles/
expect "id_rsa':"
send "PASSWORD\r"
interact
它可以正常工作,没有任何问题。那么我做错了什么?
注意:当有人发布使用Expect使用scp
或ssh
的问题时,给出的答案是使用RSA密钥。我尝试过,不幸的是,在我的一台计算机上,GNOME钥匙环中存在一些糟糕的错误,这意味着我无法从RSA密钥中删除我的密码,这正是我尝试编写上述带有if
语句的脚本的原因。所以请不要告诉我使用RSA密钥。
/usr/bin/expect << "EOD" ... EOD
。这个问题类似,它有相同的问题,但是方向相反。 - Aserre/usr/bin/expect << "EOD"
,但它仍然显示错误spawn scp -rp host:~/outfiles/ /home/USERNAME/outfiles/ Enter passphrase for key '/home/USERNAME/.ssh/id_rsa': interact: spawn id exp0 not open while executing "interact" Successful download
。 - Marses