码迷,mamicode.com
首页 > 系统相关 > 详细

<zz>linux运维自动化shell脚本小工具

时间:2016-08-07 06:12:37      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

from http://www.cnblogs.com/wang-li/p/5728461.html

linux运维shell 脚本小工具,如要分享此文章,请注明文章出处,以下脚本仅供参考,若放置在服务器上出错,后果请自负

1.检测cpu剩余百分比

技术分享
#!/bin/bash

#Inspect CPU

#Sun Jul 31 17:25:41 CST 2016

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/bin
export PATH

TERM=linux
export TERM

CpuResult=$(top -bn 1 | grep "Cpu" | awk {print $5}‘ | sed s/\..*$//g)

if [[ $CpuResult < 20 ]];then
  echo "CPU WARNING : $CpuResult" > /service/script/.cpu_in.txt
  top -bn 1 >> /service/script./cpu_in.txt
  mail -s "Inspcet CPU" wl < /service/script/.cpu_in.txt
fi
技术分享

2.检测内存

技术分享
#!/bin/bash

#Inspect Memory : If the memory is less than 500 , then send mail to wl

#Tue Aug  2 09:13:43 CST 2016


PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/bin

export PATH


MEM=$(free -m | grep "Mem" | awk {print $4})

if [[ MEM < 500 ]];then
  echo -e "Memory Warning : Memory free $MEM" > /service/script/.MemoryWarning
  mail -s "Memory Warning" wl < /service/script/.MemoryWarning
fi
技术分享

3.检测磁盘剩余空间

技术分享
#!/bin/bash

#Insepct Harddisk , If the remaining space is more than 80%, the message is sent to the wl

#Tue Aug  2 09:45:56 CST 2016

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/bin

export PATH

for RemainingSpace in $(df -h | awk {print $5}‘ | grep -v Use‘ | sed -e s/[%]//g)
do
  if [[ $RemainingSpace > 80 ]];then
    echo -e "$RemainingSpace"
    echo -e "$(df -h | grep $RemainingSpace)" > /service/script/.HarddiskWarning
    mail -s "disk Warning" wl < /service/script/.HarddiskWarning
  fi
done
技术分享

4.检测剩余Inode

技术分享
#!/bin/bash

#Inspcet Inode : If the free INODE is less than 200, the message is sent to the wl

#Tue Aug  2 10:21:29 CST 2016

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/bin

export PATH

for FreeInode in $(df -i | grep -v "Filesystem" | awk {print $4})
do
  if [[ $FreeInode < 200 ]];then
    echo -e "$(df -i | grep "$FreeInode")" > /service/script/.FreeInode
    mail -s "FreeInode Warning" wl < /service/script/.FreeInode
  fi
done
技术分享

<zz>linux运维自动化shell脚本小工具

标签:

原文地址:http://www.cnblogs.com/zhangqiang1981/p/5745272.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!