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

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

2016年02月05日 18:02:44 msdnchina 阅读数 8044linux

 版权声明:本文为博主原创文章,未经博主容许不得转载。 https://blog.csdn.net/msdnchina/article/details/50638818oracle

 

 
  1. [oracle@hosta ~]$ cat auto_transfer.sh 测试

  2. #!/usr/bin/expect -fspa

  3. set password oracle.net

  4. #downloadcode

  5. spawn scp /home/oracle/p10404530_112030_Linux-x86-64_1of7.zip oracle@192.168.188.167:/home/oracle/blog

  6. set timeout 300ip

  7. expect "oracle@192.168.188.167's password:"get

  8. set timeout 300 ------->>>>>>300表示300秒后超时,在超时以后,控制权会转移到下一行;若在超时时间以内,程序运行完,则控制权也会转移到下一行。it

  9. send "$password\r"

  10. set timeout -1 ------->>>>>>注意此处的-1,-1表示永不超时,也就是:等 scp 命令正常执行完成以后,控制权会转移到下一行。

  11. send "exit\r"

  12. expect eof

  13.  
  14. [oracle@hosta ~]$

 
  1. [oracle@hosta ~]$ ./auto_transfer.sh

  2. spawn scp /home/oracle/p10404530_112030_Linux-x86-64_1of7.zip oracle@192.168.188.167:/home/oracle/

  3. oracle@192.168.188.167's password:

  4. p10404530_112030_Linux-x86-64_1of7.zip 100% 1296MB 8.8MB/s 02:28

 

目的端:

 
  1. [oracle@single ~]$ ll

  2. total 1358916

  3. -rwxr--r-- 1 oracle oinstall 183 Feb 5 16:32 auto.sh

  4. drwxr-xr-x 8 oracle oinstall 4096 Sep 22 2011 database

  5. drwxr-xr-x 4 oracle oinstall 4096 Dec 4 10:39 hvr

  6. -rw-r----- 1 oracle oinstall 28672 Feb 5 17:07 lei1_01.dmp

  7. -rw-r--r-- 1 oracle oinstall 1194 Feb 2 17:10 lei1_imp.log

  8. -rw-r--r--. 1 oracle oinstall 33020933 Nov 4 17:44 OPatch 11.2.0.3.6_p6880880_112000_Linux-x86-64.zip

  9. -rw-r--r-- 1 oracle oinstall 1358454646 Feb 5 17:37 p10404530_112030_Linux-x86-64_1of7.zip

  10. -rwxr--r-- 1 oracle oinstall 124 Feb 5 16:24 talk.sh

  11. [oracle@single ~]$

相关文章
相关标签/搜索