expect提取性能数据cpu/disk/mem

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了expect提取性能数据cpu/disk/mem相关的知识,希望对你有一定的参考价值。


#!/usr/bin/expect

set timeout 5

foreach i {192.168.3.8 192.168.3.100} {

spawn ssh [email protected]$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

}


本文出自 “小V运维之路” 博客,谢绝转载!

以上是关于expect提取性能数据cpu/disk/mem的主要内容,如果未能解决你的问题,请参考以下文章