expect使用

scp

#!/usr/bin/expect 
if {$argc < 2} {
        send_user "usage: $argv0 src_file username ip dest_file password\n"
exit
}

set username "root" 
set password "111111" 
set src_file [lindex $argv 0] 
set dest_file [lindex $argv 1] 
set host_ip   [lindex $argv 2]

set timeout 50

spawn scp  -r $src_file $username@$host_ip:$dest_file
expect {
        "(yes/no)?"
        {
                        send "yes\n"
                        expect "*assword:"
                        {
                                send "$password\n"
                        }
        }
        "*assword:"
        {
                        send "$password\n"
        }
}
expect "100%"
expect eof

ssh執行命令

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章