我的shell脚本,我想删除密码提示为scp命令(如在https://stackoverflow.com/questions/459182/using-expect-to-pass-a-password-to-ssh/459225#459225 ),这是我迄今为止: –
#!/usr/bin/expect spawn scp $DESTINATION_PATH/exam.tar $SSH_CREDENTIALS':/'$PROJECT_INSTALLATION_PATH expect "password:" send $sshPassword"\n"; interact
在运行脚本时,我收到错误
spawn: command not found send: command not found interact: command not found
我也得到错误expect: command not found也expect: command not found ,然后我意识到的pathexpect是不正确的, expect没有安装。 所以,我做了yum install expect ,纠正了path,错误消失了。 但是仍然无法删除其他3个错误。
你正在调用剧本。
如果你说:
bash scriptname
那么#! 行被忽略,bash将这个文件当作是bash指令。 但这不是一个bash脚本,它是一个期望脚本。
#! 只有在内核被解释的情况下,脚本才能作为一个命令来运行。
请给脚本执行权限,以便您可以调用./scriptname ,或使用expect命令来启动脚本。
确保你有“期待”的工具,如果没有,做到这一点
# apt-get install expect
用下面的内容创build一个脚本文件。 (#vi / root / scriptfile)
spawn scp /path_from/file_name user_name_here@to_host_name:/path_to
expect "password:"
send put_password_here\n;
interact
用“expect”工具执行脚本文件
# expect /root/scriptfile