#!/bin/bash
ip=$ (ifconfig eth0 |grep "inet addr" | awk ' {print $} ' |cut-f1-d ":") a=$ (df-h |grep/dev/sda2 |awk ' {print $} ' |cut-f1 -B "%") #截取分区使用率
If [$a-ge] then echo "$IP the server root partition is about to have no space, please clean it up in time. "|mail-s" $IP root partition detection "[email protected]
Fi
Here I use 163 mailbox, related settings to see the link
76038868 turn from CSDN
The above is originally written, SH direct execution without error and when the usage is greater than 80 o'clock, will send the relevant warning to the mailbox, but when the crontab timed task is written as follows:
*/2 * * * */shell_script/disk_check.sh
e-mail messages received in Chinese and $ip are not properly displayed, both of the causes of the problem are environment variables, the CRONTAB runtime is not the user's environment,
For Chinese garbled problem:
Echo $LANG First look at the language environment such as: ZH_CN. GB2312
Add a line to the script: Export LANG=ZH_CN. GB2312
The problem cannot be displayed for $ip:
Add a row to the script: Source/etc/profile
Shell script detects root partition hard disk space utilization