usr/bin/expect方式免密码登录和发送文件脚本
生活随笔
收集整理的這篇文章主要介紹了
usr/bin/expect方式免密码登录和发送文件脚本
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
ssh 登錄
#!/usr/bin/expect set timeout 20 if { [llength $argv] < 3} { puts "Usage:" puts "remote_host password cmd" exit 1 } set remote_host [lindex $argv 0] set password [lindex $argv 1] set cmd [lindex $argv 2]set passwderror 0 spawn ssh $remote_host expect { "*assword:*" { if { $passwderror == 1 } { puts "password is error" exit 2 } set timeout 1000 set passwderror 1 send "$password\r" exp_continue } "*es/no)?*" { send "yes\r" exp_continue } timeout { puts "connect is timeout" exit 3 } }expect "$*" { send "$cmd\r" } send "exit\r" expect eofscp
#!/usr/bin/expect set timeout 20 if { [llength $argv] < 3} { puts "Usage:" puts "$argv0 local_file remote_path password" exit 1 } set local_file [lindex $argv 0] set remote_path [lindex $argv 1] set password [lindex $argv 2]set passwderror 0 spawn scp $local_file $remote_path expect { "*assword:*" { if { $passwderror == 1 } { puts "password is error" exit 2 } set timeout 1000 set passwderror 1 send "$password\r" exp_continue } "*es/no)?*" { send "yes\r" exp_continue } timeout { puts "connect is timeout" exit 3 } }轉(zhuǎn)載于:https://my.oschina.net/u/727875/blog/1531829
總結(jié)
以上是生活随笔為你收集整理的usr/bin/expect方式免密码登录和发送文件脚本的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [ECMAScript] 举例说明你对e
- 下一篇: 51单片机入门——8X8点阵LED