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

转载于:https://my.oschina.net/wangyli/blog/3057301

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值