首页 > 其他 > 详细

expect简单用法

时间:2014-05-15 16:59:38      阅读:389      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 #!/usr/expect/bin/expect -f
 2 
 3 
 4 set loginuser [lrange $argv 0 0]
 5 set loginpass [lrange $argv 1 1]
 6 set ipaddr [lrange $argv 2 2]
 7 set port   [lrange $argv 3 3]
 8 set timeout [lrange $argv 4 4]
 9 set from [lrange $argv 5 5]
10 set to [lrange $argv 6 6]
11 set cmd_prompt "#|~|]"
12 
13 if { $loginuser == "" || $loginpass == "" || $ipaddr == "" || $port == "" || $timeout == "" || $from == "" || $to == "" }  {
14       puts "Usage: <user> <password> <ip> <port> <timeout> <from> <to> \n"
15       exit 1
16 }
17 #-------------------------------------------------- 
18 if { [file isfile $from ]==1 } { 
19     spawn scp -P $port $from $loginuser@$ipaddr:$to 
20 } else {
21     spawn scp -P $port -r $from $loginuser@$ipaddr:$to 
22 }
23 set timeout $timeout
24 
25 expect {
26 -re "assword:" {
27 send "$loginpass\r"
28 } -re "Permission denied, please try again." {
29 puts "\nERROR_PASSWORD"
30 exit
31 } -re "port $port: Connection refused" {
32 puts "ERROR_PORT"
33 exit
34 } -re "Connection closed" {
35 puts "ERROR_UNKNOW"
36 exit
37 } timeout {
38 puts "ERROR_TIMEOUT_OR_IP"
39 exit
40 } eof {
41 puts "ERROR_UNKNOW"
42 exit
43 }
44 }
45 
46 expect {
47 -re "assword:" {
48 puts "\nERROR_USERNAME_OR_PASSWORD"
49 exit
50 } -re "100%" {
51 puts "ERROR_NONE"
52 }
53 }
54 
55 #--------------------------------------------------
56 expect {
57 -re $cmd_prompt {
58 send "exit\r"
59 }
60 }
61 expect eof
62 
63 exit
64 #interact
bubuko.com,布布扣

 

expect简单用法,布布扣,bubuko.com

expect简单用法

原文:http://www.cnblogs.com/gdutzzh/p/3726407.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!