查看服务器状态
#!/bin/bash
declare -A RESULT
RESULT=()
function getinfo() {
IP=$1
CPU=$(ssh $IP -p 22 "atop -r /var/log/atop/atop_$(date -d last-day +%Y%m%d).1 -b 20:00|grep CPU|head -n1|awk '{print \$4}'")
MEM=$(ssh $IP -p 22 "atop -r /var/log/atop/atop_$(date -d last-day +%Y%m%d).1 -b 20:00|grep MEM|head -n1|awk '{print \$4 \$7 \$10}'|awk -F 'G' '{printf (\"%.1f%\",(\$2+\$3)/\$1*100)}'")
DISK=$(ssh $IP -p 22 "df -h|grep sda1|awk '{print \$5}'")
DISK_BUSY=$(ssh $IP -p 22 "atop -r /var/log/atop/atop_$(date -d last-day +%Y%m%d).1 -b 20:00|grep DSK|head -n1|awk '{print \$5\" \"\$6}'")
eth_speed=$(ssh $IP -p 22 "atop -r /var/log/atop/atop_$(date -d last-day +%Y%m%d).1 -b 20:00|grep em1|head -n1|awk '{print \$4}'")
RESULT+=([$IP]="$IP, $CPU, $MEM, $DISK, $DISK_BUSY, $eth_speed")
}
cd /home/njxj/execl
for ip in `cat iplist|grep -v "^$" |grep -v "^#"`;do
getinfo $ip
done
for key in $(echo ${!RESULT[*]});do
echo "${RESULT[$key]}" >> result.csv
done