Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1156686
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: Python/Ruby

2012-10-18 11:44:34

 以下分别是三个脚本,分别对流量使用、磁盘空间使用、mysql健康状况进行检查,只要定个计划任务即可,还可以及时发送邮件、短信的。
##URL http://blog.chinaunix.net/uid/25046147.html
##name gavin && 随风飘云
##Date 2012-10-08

流量使用状况检测:
#!/bin/bash
while : ; do
      time=`date +%m"-"%d" "%k":"%M`
      day=`date +%m"-"%d`
      rx_before=`ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`
      tx_before=`ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`
      sleep 2
      rx_after=`ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`
      tx_after=`ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`
      rx_result=$[(rx_after-rx_before)/256]
      tx_result=$[(tx_after-tx_before)/256]
      echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps"
      sleep 2
done

磁盘空间使用状况检测:

#!/bin/bash
IP=`ifconfig eth0|sed -n '2p'|awk '{print $2}'|cut -c 6-`
SPACE=`df |sed -n '/\/$/p'|awk '{print $4}'|sed 's/%//'`
if [ $SPACE -ge 90 ];then
  echo "The /  disk is full"
fi

mysql存活健康状况检测

#!bin/bash
##
##
CT=`date |awk -F " " '{print $6}'| cut -c 3,4`
DATE=`date +"$CT"%m%d`
TIME=`date +%H:`
HNAME=`hostname`
echo $DATE $TIME
cat db140.iqnode.cn.err|grep "$DATE"|grep "$TIME"|grep "ERROR"
if [ $? == 1 ];then
  echo "well"
else
  echo "bad"
fi

阅读(1481) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

随风飘云2012-10-18 11:46:18