From http://www.cnblogs.com/wang-li/p/5728461.html
Linux ops shell script gadget, if you want to share this article, please indicate the source of the article, the following script is for reference only, if the error placed on the server, the consequences please be conceited
1. Detecting CPU percent remaining
#!/bin/Bash#inspect Cpu#sun Jul3117:25:The CST2016path=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport pathterm=Linuxexport termcpuresult=$ (top-bn1 |Grep"Cpu" |Awk‘{Print $}' |sed s/\. *$//g ' ) if [[$ Cpuresult < 20]]; then echo "CPU WARNING: $CpuResult " >/service/script/.cpu_ In.txt top-bn cpu_in.txt Mail-s "inspcet cpu" WL </service/script/.cpu_in.txtfi
2. Detecting Memory
#!/bin/Bash#inspect Memory:if the Memory isLess than500,ThenSend mail to Wl#tue209:13:CST2016path=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport pathmem=$ (free-m |Grep "mem" | awk {print $4} ' ' 500]]; then echo-e "memory warning:memory free $MEM " >/service/script/ "memory warning "WL </service/script/. Memorywarningfi
3. Detecting disk space remaining
#!/bin/bash#insepct harddisk, If the remaining space isMore than90D, the message is sent to the Wl#tue209:45:+ CST2016path=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport PATHFor RemainingspaceIn $ (df-h |Awk‘{Print $}' |Grep-v‘Use' |Sed-e‘S/[%]//g ' ) do if [[$RemainingSpace > 80]]; Then echo-e $ Remainingspace "echo-e "$ (Df-h | grep $RemainingSpace) "disk warning "WL </service/script/. harddiskwarning fidone
4. Detecting remaining Inode
#!/bin/Bash#inspcet Inode:if theFree INODE isLess than200, the message is sent to the Wl#tue210:21st:CST2016path=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wl/Binexport PATHFor FreeinodeIn $ (Df-i |Grep-v"Filesystem" |Awk‘{print $4} ) do if [[$FreeInode < 200]];then echo-e $ (Df-i | grep " ">/service/script/. Freeinode mail-s "freeinode warning "WL </service/script/. Freeinode fidone
<zz>linux OPS automation shell scripting gadget