07 监控100台服务器磁盘利用率

#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

HOST_INFO=host.info
for IP in $(awk '/^[^#]/ {print $1}' $HOST_INFO); do
    USER=$(awk -v ip=$IP 'ip==$1 {print $2}' $HOST_INFO)
    PORT=$(awk -v ip=$IP 'ip==$1 {print $3}' $HOST_INFO)
    TMP_FILE=/tmp/disk.tmp
    ssh -p $PORT $USER@$IP 'df -h' > $TMP_FILE
    USE_RATE_LIST=$(awk -v OFS="=" '/^\/dev/ {print $NF, int($5)}' $TMP_FILE)
    for USE_RATE in $USE_RATE_LIST; do
        PART_NAME=${USE_RATE%=*}
        USE_RATE=${USE_RATE#*=}
        if [ $USE_RATE -ge 80 ]; then
            echo -e "$IP \n Warning: $PART_NAME Partition usage ${USE_RATE}%!"
        fi
    done
done




# Usage:
# ssh-keygen
# ssh-copy-id -p <PORT> <USER>@<IP>

# HOST_INFO:
# <IP> <USER> <PORT>

 

上一篇:优惠券预测——数据探索2


下一篇:job的简单创建