#!/usr/bin/expect
set timeout 5
foreach i {192.168.3.8 192.168.3.100} {
spawn ssh root@$i
expect {
"*yes/no" { send "yes\r"; exp_continue}
"*password:" { send "vision\r" }
}
expect "]*"
send "mkdir -p /root/${i}performance\r"
expect "]*"
send "free -m >/root/${i}performance/mem.txt\r"
expect "]*"
send "df -Th >/root/${i}performance/diskmem.txt\r"
expect "]*"
send "top -bn1 | grep 'Cpu(s)' >/root/${i}performance/cpu.txt\r"
sleep 1
spawn scp -rp $i:/root/${i}performance /root/
expect "*password*"
send "vision\r"
expect eof
sleep 2
}
本文转自chenzudao51CTO博客,原文链接:http://blog.51cto.com/victor2016/1915392 ,如需转载请自行联系原作者