#!/usr/bin/expect -f
set ip [lindex $argv 0]
set timeout 5
spawn ssh root@$ip
expect {
"(yes/no)?" {send "yesr"}
"*password:" {send "123456@r"}
}
expect "password:"
send "123456@r"
#interact #留在子进程
expect "#"
send "ifconfig
eth0 |awk '$1 ~ /inet/ { print $2}' > /tmp/$ip.txtr"
expect "#"
send "exec uptime|awk '{print $1,$10}'| sed 's!,!!g' >> /tmp/$ip.txtr"
spawn /usr/bin/scp root@$ip:/tmp/$ip.txt /home
expect "password:"
send "123456@r"
expect "~]# "
#send "exitr"