写个一个expect的脚本,但是要配合for循环执行,因为怕与expect符号冲突,所以在调用awk的时候没写太复杂的脚本,像替换我都用管道给sed来完成。
#!/usr/bin/expect -f
set ip [lindex $argv 0]
set timeout 5
spawn ssh root@$ip
expect {
"(yes/no)?" {send "yes\r"}
"*password:" {send "123456@\r"}
}
expect "password:"
send "123456@\r"
#interact #留在子进程
expect "#"
send "ifconfig eth0 |awk '\$1 ~ /inet/ { print \$2}' > /tmp/$ip.txt\r"
expect "#"
send "exec uptime|awk '{print \$1,\$10}'| sed 's!,!!g' >> /tmp/$ip.txt\r"
spawn /usr/bin/scp root@$ip:/tmp/$ip.txt /home
expect "password:"
send "123456@\r"
expect "~]# "
#send "exit\r"
阅读(2348) | 评论(0) | 转发(0) |