1

I'm currently trying to automate a file transfer using the scp command with a shell script and the expect package. Based on what I've seen it seems that I should have #!/usr/bin/expect -f But when I did that I still get the errors:

DirectoryChange.sh: line 33: spawn: command not found
couldn't read file "*Password:*": no such file or directory
DirectoryChange.sh: line 35: send: command not found
DirectoryChange.sh: line 36: interact: command not found

The code I have works something along these lines:

#!/usr/bin/expect -f

repository=$PWD"/subdirectory/"
set pass "***********"

cd $repository
spawn scp -r user@host:/copyDirectory/ .
expect "*Password:*"
send "${pass}\r";
interact
4

2 回答 2

1

将密码存储在脚本或任何其他文件中是一种不好的做法。请改用 SSH 身份验证密钥。

看看这个教程

于 2013-06-02T22:54:53.167 回答
0

看起来你正在调用你的期望脚本,比如sh DirectoryChange.sh. 显然sh不是期望脚本的正确解释器。

  • 更改文件扩展名:“.sh”用于 shell 脚本
  • 确保它具有执行权限,然后启动它./DirectoryChange.exp
  • repository=$PWD"/subdirectory/"不是如何在期望中分配变量。删除此行并将该行编辑cdcd subdirectory
  • 您不必与 scp 交互,因此将最后一行更改为expect eof
于 2013-05-30T18:02:57.090 回答