码迷,mamicode.com
首页 > 编程语言 > 详细

expect脚本语言用法示例

时间:2015-05-20 17:56:29      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:

#!/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  

  

expect脚本语言用法示例

标签:

原文地址:http://www.cnblogs.com/limt/p/4517720.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!