需求: 使用scp下載資料,幫使用者自動輸入yes之後再輸入passward,或是直接輸入password
#!/usr/bin/expect
set ip [lindex $argv 0]
set pass "password"
spawn scp root@$ip:/folder/filename .
expect {
"(yes/no)?"
{
send "yes\r"
expect {
password: {send "$pass\r"; exp_continue}
}
}
timeout {
exit 1
}
password: {send "$pass\r"; exp_continue}
}
interact
----------------------------------------------------------------------