cpu、内存、缓存、硬盘使用率
1、cpu
./bunsan2.sh uptime < servers.txt | awk '{print $11 }' |sed 's/,//g'
#!/bin/bash cpu_load=$(uptime | awk '{print $11 }' |sed 's/,//g') echo $cpu_load > /home/data/wuxi147_cpu.txt scp /home/data/wuxi147_cpu.txt root@58.241.41.150:/usr/local/apache2/htdocs/
2、内存
#!/bin/bash total=$(free -m|grep Mem|awk '{print $2}') used=$(free -m|grep Mem|awk '{print $3}') echo "$used/$total"|bc -l |awk '{printf "%.2f%\n",$1*100 }' > /home/data/wuxi147_memory.txt scp /home/data/wuxi147_memory.txt root@58.241.41.150:/usr/local/apache2/htdocs/
#!/bin/bash count=1 for i in {1..6..1} do total=$(free -m|grep Mem|awk '{print $2}') used=$(free -m|grep Mem|awk '{print $3}') echo "$used/$total"|bc -l > /home/data/memory1.txt awk '{printf "%.2f%\n",$1*100 }' /home/data/memory1.txt > /usr/local/apache2/htdocs/wuxi150_memory.txt echo $i sleep 10 done
3、磁盘
#!/bin/bash Location=/dev/sda3 Disk_Used_Rate=$(df -h | grep $Location | awk '{print $5}') echo $Disk_Used_Rate > /home/wuxi147_disk.txt scp /home/wuxi147_disk.txt root@58.241.41.150:/usr/local/apache2/htdocs/
#!/bin/bash Location=/dev/sda3 total=$(df -h |grep $Location | awk '{print $2}'|sed 's/G//g' ) used=$(df -h |grep $Location | awk '{print $4}'|sed 's/G//g' ) echo "$used/$total"|bc -l > /home/data/wuxi147_disk.txt scp /home/data/wuxi147_disk.txt root@58.241.41.150:/usr/local/apache2/htdocs/
4、缓存
#!/bin/bash total=$(free -m|grep Mem|awk '{print $2}') used=$(free -m|grep Mem|awk '{print $7}') echo "$used/$total"|bc -l > /home/wuxi147_cache.txt scp /home/wuxi147_cache.txt root@58.241.41.150:/usr/local/apache2/htdocs/