Idle egg Pain wrote a code
Example 1
The code is as follows |
Copy Code |
#!/bin/sh max=99 list=$ (Df-h|awk ' {print $} ' |sed ' s/%//g ' |sed '/[a-za-z]/d ')
Mailto= "135********@139.com" Subject= "$ (hostname) ' s partition alert" Content= "$ (hostname) ' s used detail:n $ (df-h |awk ' {print$6,$5} ') ntime:$ (date-d today + '%y-%m-%d%h:%m:%s ')"
For PERCENT in $LIST; Todo If [$PERCENT-gt $MAX]; Then Echo-e "MAX Used: $PERCENT%n$content" | Mail-s "$subject" $mailto Exit Fi Done
Exit |
We can automatically join the scheduled task to execute the
Example 2 (function: Monitor disk space size and automatically report)
The code is as follows |
Copy Code |
#!/bin/sh #make by ItBit Init () { ipadd= ' Ifconfig|grep 172.18|awk ' {print $} ' |sed ' s/addr://g '; Nowtime= ' Date +%f-%h:%m '; Mailto= ""; mail_sub= "!**report-disk Capacity the **!"; Tmpfile=/tmp/iamatmpfile.tmp } Mhead () { echo "" > $tmpfile; echo "From: $IPADD" >> $tmpfile echo "State:report" >> $tmpfile echo "Reportby:$0" >> $tmpfile echo "DateTime: $NOWTIME" >> $tmpfile echo "Info:codfei" >> $tmpfile echo "" >> $tmpfile; } Smail () { Mail-s "$MAIL _sub" $MAILTO < $tmpfile } Init For x in ' df | Grep/dev | awk ' {print $} ' | Sed ' s/%//g ' Todo If [$x-GT 89]; Then Mhead; Df-h >> $tmpfile; Smail; Exit 0; Fi Done |