1. linux下expect腳本問題
#!/usr/bin/expect-f
if{$argc!=1}{
puts"usage:$argv0IP"
exit1
}else{
setIP[lindex$argv0]
}
setpingcmd[format"ping-c100%s"$IP]
settimeout6000
#比如遠程用戶叫做test
setdestusertest
#比如遠程伺服器IP為如下
setdestip192.168.0.123
setdestpath"$destuser@$destip"
#比如用戶密碼叫做test
setdestpasswordtest
#ssh登錄
spawnssh$destpath
#######################
expect{
-re".*yes/no.*"{
exp_send"yes "
exp_continue
}
-re".*assword.*"{
exp_send"$destpassword "
}
}
#比如ssh登錄以後的提示符是test@Testserver>
expect{
-re".*test@Testserver.*"{
exp_send"$pingcmd "
}
}
expect{
#如果輸出timeout字元,則Control+C結束pingcmd
#這里用的是DestinationHostUnreachabl替換timeout。因為本人機器上沒有timeout.
-re".*DestinationHostUnreachabl.*"{
#輸入Control+c
exp_send"