本文共 617 字,大约阅读时间需要 2 分钟。
#!/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
}