天天看点

SHELL一些监控的脚本(模块)

1,apache的源码安装脚本

#!/bin/bash

##auther xiaosonglin

##date 2013-06-08

###apache install

PATH=`echo $PATH`

rpm -qa |grep httpd

if [ $? -eq 0 ];then

  echo "apache alredy install" >apac.log

  rpm -e httpd

else

    echo "apache not install" >>apac.log

     wget http://192.168.18.254/abc/httpd-2.2.16.tar.bz2  局域网类的地址

        if [ $? -ne 0 ];then

           echo "wget ERROR" >>apac.log

          else

              tar fjvx httpd-2.2.16.tar.bz2 

                 cd httpd-2.2.16

                 ./configure

              make && make install

       fi

fi

#######

一个httpd启动脚本,放到/etc/init.d/下,可以使用service apache2 start|restart|status|stop    

中apache可自定义

##apache replace httpd

##auther xsl

##date

start () {

 /usr/sbin/httpd

}

stop () {

 kill -s QUIT httpd

status () {

 elinks http://192.168.18.213 -dump >/dev/null   本机

  if [ $? -eq 0 ];then

   echo "apache is running"

  else

    echo "apache is down"

  fi

restart () {

 sleep 3

## main

case $1 in

start)

 start;;

stop)

 stop;;

status)

 status;;

restart)

  restart;;

*)

  echo  "Usage: ./case start|stop|restart|status "

esac

######

2,监控磁盘

#DISK

#disk () {

#show disk

IP=` ifconfig eth0|awk 'NR==2'|awk '{print $2}'|awk -F: '{print $2}'`

DISK_LIST=`fdisk -l |grep Disk |awk -F , '{print $1}'> disk_list`

DISK_COUNT1=`cat disk_list|wc -l`

let DISK_COUNT2=" $DISK_COUNT1 + 1 "

for (( i=1;i<$DISK_COUNT2;i++ ))

do

  DISK_NAME=`awk NR==$i disk_list|awk '{print $2}'|tr -d ":" `

  echo "`awk NR==$i disk_list`"

  df -Th|grep $DISK_NAME

#  echo -e "\n"

##disk_use_mom

  df -Th|grep $DISK_NAME|awk '{print $6}'|tr -d "%" > disk_use

     for i in `cat disk_use`

        do

            if [ $i -gt 90 ]

             then

                echo "$IP  disk full,please check"

             fi

     done

done

#}