expect脚本语言用法示例

#!/usr/bin/expect                                                                                                                   
                                                                                                                                    
set hostname [lindex $argv 0]                                                                                                       
set username [lindex $argv 1]                                                                                                       
set passwd [lindex $argv 2]                                                                                                         
set dbname [lindex $argv 3]                                                                                                         
                                                                                                                                    
                                                                                                                                    
set timeout 10                                                                                                                      
#spawn /usr/bin/ssh $username@$hostname                                                                                             
#expect {                                                                                                                           
#           "yes/no" { send "yes";exp_continue}                                                                                     
#           "password:"{send "$passwd";}                                                                                            
#}                                                                                                                                  
                                                                                                                                    
spawn /usr/kerberos/bin/telnet $hostname                                                                                            
expect "login:" {send "$username\r"}                                                                                                
expect "Password:" {send "$passwd\r"}                                                                                               
send "export LANG=C\r"                                                                                                              
send "cat /etc/redhat-release|sed 's/ //g'|awk '{ print \"OSLEVEL:\"\$1\":\"}'\r"                                                   
send "cat /proc/meminfo |grep MemTotal|awk  '{ print \"MEMSIZE:\" \$2\$3\":\" }'\r"                                                 
send "cat /proc/cpuinfo|grep \"physical id\"|sort|uniq |wc -l|awk '{ print \"CPU:\"\$1\":\"}'\r"                                    
send "db2 connect to $dbname\r"                                                                                                     
send "db2  -x \"select 'DBSIZE:',sum(TBSP_USED_SIZE_KB)/1024/1024,':'   from SYSIBMADM.TBSP_UTILIZATION\"\r"
send "db2 terminate\r"                                                                                                              
send "exit\r"                                                                                                                       
                                                                                                                                    
expect eof  

  

posted @ 2015-05-20 17:27  圣光救赎者  阅读(420)  评论(0编辑  收藏  举报