测试linux中expect的timeout参数的作用

 

[oracle@hosta ~]$ cat auto_transfer.sh 
#!/usr/bin/expect -f
set password oracle
#download
spawn scp /home/oracle/p10404530_112030_Linux-x86-64_1of7.zip [email protected]:/home/oracle/
set timeout 300
expect "[email protected]'s password:"
set timeout 300  ------->>>>>>300表示300秒后超时,在超时之后,控制权会转移到下一行;若在超时时间之内,程序运行完,则控制权也会转移到下一行。
send "$password\r"
set timeout -1   ------->>>>>>注意此处的-1,-1表示永不超时,也就是:等 scp 命令正常执行完成之后,控制权会转移到下一行。
send "exit\r"
expect eof

[oracle@hosta ~]$
[oracle@hosta ~]$ ./auto_transfer.sh 
spawn scp /home/oracle/p10404530_112030_Linux-x86-64_1of7.zip [email protected]:/home/oracle/
[email protected]'s password: 
p10404530_112030_Linux-x86-64_1of7.zip                              100% 1296MB   8.8MB/s   02:28    


目的端:

[oracle@single ~]$ ll
total 1358916
-rwxr--r--  1 oracle oinstall        183 Feb  5 16:32 auto.sh
drwxr-xr-x  8 oracle oinstall       4096 Sep 22  2011 database
drwxr-xr-x  4 oracle oinstall       4096 Dec  4 10:39 hvr
-rw-r-----  1 oracle oinstall      28672 Feb  5 17:07 lei1_01.dmp
-rw-r--r--  1 oracle oinstall       1194 Feb  2 17:10 lei1_imp.log
-rw-r--r--. 1 oracle oinstall   33020933 Nov  4 17:44 OPatch 11.2.0.3.6_p6880880_112000_Linux-x86-64.zip
-rw-r--r--  1 oracle oinstall 1358454646 Feb  5 17:37 p10404530_112030_Linux-x86-64_1of7.zip
-rwxr--r--  1 oracle oinstall        124 Feb  5 16:24 talk.sh
[oracle@single ~]$ 

 

你可能感兴趣的:(linux,expect)