俺的这个磁盘空间监控,大量使用了awk,嘿嘿,enjoy it!
#!/bin/sh
#disk_monitor.sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
LANG=zh_CN.gbk
export PATH LANG
CRITICAL=90
CONTACTS_LIST="联系人手机号码"
HOST=$(/sbin/ifconfig | awk -F'[ ]*|:' '($0~/inet addr:/ && $0!~/Mask:255.255.255.255|inet addr:127.0.0.1/){printf("%s ",$4)}END{print}')
eval $(df -k | awk -F"[ ]*|%" '(NR>1){ if($5>i) {i=$5 ; partition_used_max=$NF} }END{print "PARTITION_USED_MAX="partition_used_max ; print "PARTITION_USED_MAX_PER="i }')
eval $(df -i | awk -F"[ ]*|%" '(NR>1){ if($5>i) {i=$5 ; inode_used_max=$NF} }END{print "INODE_USED_MAX="inode_used_max ; print "INODE_USED_MAX_PER="i }')
# out something like this:
# PARTITION_USED_MAX=/home
# PARTITION_USED_MAX_PER=78
# INODE_USED_MAX=/usr
# INODE_USED_MAX_PER=18
# of course , scan this definition twice
#USED=$(df -k | awk -F"[ ]*|%" '(NR>1){print $5}' | sort -nr | head -1)
#INODE_USED=$(df -i | awk -F"[ ]*|%" '(NR>1){print $5}' | sort -nr | head -1)
if [ $PARTITION_USED_MAX_PER -ge $CRITICAL ] || [ $INODE_USED_MAX_PER -ge $CRITICAL ]
then
for phone in $CONTACTS_LIST
do
SMS_MESSAGE="DISK Warn:$HOST+disk+space+$PARTITION_USED_MAX+used+$PARTITION_USED_MAX_PER%;+inode:$INODE_USED_MAX+used+$INODE_USED_MAX_PER%"
/usr/bin/wget -O result.txt "http://你的短信发送服务器?message=$SMS_MESSAGE"
done
fi
阅读(545) | 评论(0) | 转发(0) |