【问题标题】:Using expect, spawn with scp使用期望,使用 scp 生成
【发布时间】:2013-05-26 09:54:51
【问题描述】:

我目前正在尝试使用带有 shell 脚本和期望包的 scp 命令自动执行文件传输。根据我所看到的,我似乎应该有 #!/usr/bin/expect -f 但是当我这样做时,我仍然得到错误:

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

我的代码是这样工作的:

#!/usr/bin/expect -f

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

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

【问题讨论】:

    标签: shell expect scp spawn


    【解决方案1】:

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

    看看this tutorial

    【讨论】:

      【解决方案2】:

      看起来您正在调用诸如sh DirectoryChange.sh 之类的expect 脚本。显然 sh 不是 expect 脚本的正确解释器。

      • 更改文件扩展名:“.sh”用于 shell 脚本
      • 确保它具有执行权限,然后使用./DirectoryChange.exp 启动它
      • repository=$PWD"/subdirectory/" 不是如何在期望中分配变量。删除此行并将cd 行编辑为cd subdirectory
      • 你不必和scp交互,所以把最后一行改成expect eof

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-05
        • 1970-01-01
        • 2017-12-31
        • 1970-01-01
        • 1970-01-01
        • 2015-12-04
        • 2017-11-17
        • 2016-08-21
        相关资源
        最近更新 更多