shell3

例一:监控httpd是否正常运行并自动开启

#!/bin/bash
port=$(nmap -sT localhost | grep 'http$' |awk '{print $2}')
riqi=$(date +"%Y-%m-%d %H:%M")
if [ "$port" == "open" ];then
        echo "$riqi http is ok" >>/tmp/httpok.txt
else
        /usr/local/apache2/bin/apachectl start
        echo "$riqi httpd is restart" >>/tmp/httperror.txt
fi

 

例二:多台服务器查看内存

#!/bin/bash

while read server;do
        ssh -n $server "$@" 2>&1 |sed "s/^/$server: /" &
done
wait

./bunsan2.sh free -m < servers.txt 

 例三:磁盘使用率

#!/bin/bash
Location=/dev/sda5
Disk_Used_Rate=$(df -h | grep $Location | awk '{print $5}')
echo $Disk_Used_Rate >> /var/www/cipangshiyonglv.txt

例四:内存使用率

#!/bin/bash
total=$(free -m|grep Mem|awk '{print $2}')
used=$(free -m|grep Mem|awk '{print $3}')
echo "$used/$total"|bc -l >> /var/www/neicunshiyonglv.txt

 

posted @ 2015-04-03 11:09  kin2321  阅读(164)  评论(0编辑  收藏  举报