#!/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 [email protected] $hostname #expect { # "Yes/no" {s End "yes"; exp_continue} # "P Assword: "{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, ': ' fr Om Sysibmadm. Tbsp_utilization\ "\ r" send "DB2 terminate\r" Send "exit\r" Expect EOF
Expect scripting language Usage example