当前位置:Linux教程 - Shell - shell - expect使用一例

shell - expect使用一例

expect使用一例
2004-04-23 15:18 pm
来自:Linux文档
现载:Www.8s8s.coM
地址:无名

Using Expect to do it...
改一下ftp 成telnet ,與Prompt的地方..與你要做的事情就好了...

代码:

#!/usr/local/bin/expect --
set send_slow {10 .1}
eval spawn ftp 10.1.1.1
set timeout 10
expect {
timeout {
send_user "TIMEOUT:10.1.1.1 "
exit 0;
}
"):" { send "apile " }
"refused" {
send_user "Connection Failed "
exit 0;
}
}

set timeout 5
expect {
timeout { exit 0}
"sword:" { send "apile123 " }
}
#---- work start here
set timeout 5
expect {
timeout {
send_user "密碼錯誤 "
exit 0
}
">" { send "cd c:abccde " }
}
set timeout 5
expect {
timeout {
send_user "Something Error "
exit 0
}
">" { send "get "abc.txt " }
}
set timeout 600
expect {
timeout {
send_user "Something Error "
exit 0
}
">" { send "bye " }
}