- 论坛徽章:
- 3
|
[ 本帖最后由 李满满 于 2014-11-24 11:51 编辑 ]
学生党:飘过~个人写的完美版~不过需要你对方know_host存在最好是用提前分发一下,不然会假死状态,不过ctrl+z结束掉再次执行就好了~
[root@python-hacker python_shell]#cat auto_scp.exp
#!/usr/bin/expect
if { $argc != 5 } {
send_user "usage: expect auto_scp.exp localpath rusername rpassword remoteip remotepath\n"
exit
}
set local_ph [lindex $argv 0]
set rmote_ur [lindex $argv 1]
set rmote_pw [lindex $argv 2]
set rmote_ip [lindex $argv 3]
set rmote_ph [lindex $argv 4]
spawn scp -o StrictHostKeyChecking=no -P22 -r -p ${local_ph} ${rmote_ur}@${rmote_ip}:${rmote_ph}
expect {
"*No*" {send_user [exec echo "1" >> .res]}
"yes/no" {exp_send "yes\n" }
"*password:" {exp_send "$rmote_pw\n" }
}
wait
expect eof
exit
[root@python-hacker python_shell]# ./auto_scp.exp auto_scp.exp yhsafe yinhe@123 172.24.10.2 /home/yhsafe/
spawn scp -o StrictHostKeyChecking=no -P22 -r -p auto_scp.exp [email]yhsafe@172.24.10.2[/email]:/home/yhsafe/
[email]yhsafe@172.24.10.2[/email]'s password:
auto_scp.exp 100% 661 0.7KB/s 00:00
|
|