1, disk use warning and send mail
#!usr/bin/bash
#df-th|grep '/$ ' This is the record that gets the memory used
#后面两句是获取内存的使用率
disk= ' df-th|grep '/$ ' |awk ' {print $ (NF-1)} ' |awk-f '% ' ' {print '} '
Mail_user=natasha
If [$disk-ge];then
echo "' Date +%f-%h ' disk:${disk}%" |mail-s "Disk war ..." $mail _user
Fi
2, Memory usage warning and sending mail
#!/usr/bin/bash
Mem_used= ' Free-m|grep ' ^mem: ' |awk ' {print $} '
Mem_total= ' Free-m|grep ' ^mem: ' |awk ' {print $} '
mem_per=$ ((mem_used*100/mem_total))
War_file=/tmp/mem_war.txt
RM-RF $war _file# This step is to prevent this file from being present the next time you execute the script
If [$mem _per-ge 2];then
echo "' Date +%f-%h ' memory:${mem_per}%" > $war _file
Fi
If [-F $war _file];then
Mail-s "Mem war ..." Root < $war _file
Fi
Author Profile:
Chen Zhike (Headline number: the strong twist of the melon is not delicious currently working in China's largest android application software company, as a senior engineer , now the company is a PHP development engineer, Python development engineer, senior Operations engineer, the public number "pencil school" operation and maintenance of content co-author. *
Pencil Study Garden : It resource sharing | Knowledge sharing, being the primary programmer's beacon
Shell script Instance-memory disk usage warning