linux运维shell 脚本小工具,如要分享此文章,请注明文章出处,以下脚本仅供参考,若放置在服务器上出错,后果请自负
1.检测cpu剩余百分比
#!/bin/bash #Inspect CPU #Sun Jul :: CST 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 | grep "Cpu" | awk '{print $5}' | sed 's/\..*$//g') ]];then echo "CPU WARNING : $CpuResult" > /service/script/.cpu_in.txt top -bn >> /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 , then send mail to wl #Tue Aug :: CST 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}') ]];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 %, the message is sent to the wl #Tue Aug :: CST 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 ]];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 , the message is sent to the wl #Tue Aug :: CST 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 ]];then echo -e "$(df -i | grep "$FreeInode")" > /service/script/.FreeInode mail -s "FreeInode Warning" wl < /service/script/.FreeInode fi done
Time : 2016-08-02 10:56:00
Name: 王 李
Mail:w18030432178@outlook.com