为什么SFTP自动化与期待发送密码后挂机? [英] Why does automating SFTP with Expect hang after sending the password?

查看:164
本文介绍了为什么SFTP自动化与期待发送密码后挂机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从自动化,我的Linux服务器的一些文件上传到一个支持FTP的Windows服务器上。我成功地人工手动操作使用SFTP,然后发出的的命令。然而,从cron调用时,我的剧本一直停密码。

下面是code我试图使用方法:

 #!的/ usr / bin中/预期
#!/ bin / sh的
明确
产卵SFTP remoteuser@43.123.0.10
预计密码
发送世界
预计EOF

既然这样,它每次都要求输入密码停止。为什么没有发送世界完成密码对话框?

更新:

 #!的/ usr / bin中/预期
#!/ bin / sh的
明确
产卵SFTP remoteuser@43.123.0.10
期望remoteuser@43.123.0.10's密码
发送世界
预计EOF

现在我得到以下错误:

  xml_reports.sh:5号线:产卵:命令未找到
无法读取文件remoteuser@43.123.0.10's~~V密码:没有这样的文件或目录
xml_reports.sh:7号线:发送:命令未找到
无法读取文件EOF:没有这样的文件或目录


解决方案

尝试这样的:

 #!/斌/庆典
预计-c
产卵SFTP remoteuser@XX.XX.XX.XX
预计\\密码\\
发送\\密码\\ r \\
相互作用

例如: http://www.techtrunch.com/scripting/lazy-管理员部分-2

I am attempting to automate uploading some files from my Linux server to an FTP-enabled Windows server. I am successfully doing so manually using SFTP and then issuing the put command. However, when called from cron, my script keeps stopping for a password.

Below is the code I am attempting to use:

#!/usr/bin/expect
#!/bin/sh
clear
spawn sftp remoteuser@43.123.0.10
expect "password"
send "world"
expect eof

As it stands, it stops each time to request a password. Why doesn't send "world" complete the password dialog?

UPDATE:

#!/usr/bin/expect
#!/bin/sh
clear
spawn sftp remoteuser@43.123.0.10
expect "remoteuser@43.123.0.10's password:"
send "world"
expect eof

Now I get the following error:

xml_reports.sh: line 5: spawn: command not found
couldn't read file "remoteuser@43.123.0.10's password:": no such file or directory
xml_reports.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory

解决方案

Try like this:

#!/bin/bash
expect -c "
spawn sftp remoteuser@XX.XX.XX.XX
expect \"password\"
send \"PASSWORD\r\"
interact "

Example : http://www.techtrunch.com/scripting/lazy-admins-part-2

这篇关于为什么SFTP自动化与期待发送密码后挂机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆