问题原文
原帖链接 · tanmayghosh2507 · CC BY-SA 3.0
I have a ubuntu server, and facing frequent space issue, i.e. logs are eating up lot of disk space. So, I want a check to be applied, so that whenever there is less than 5 GB free disk space, I should get an e-mail notification, so that I can delete the logs. How can I configure this. Do I need any other application?
已采纳解答
原帖链接 · Calimo · CC BY-SA 3.0
On my Ubuntu server, I have the following script in /etc/cron.daily that alerts me by email whenever /dev/sdc (my /srv partition) has less than 200MB of free space.
ALERT=200
UNIT=M
PARTITION=/dev/sdc
df -B$UNIT | grep "^$PARTITION" |
while read partition size used free perc mnt ;
do
free_space=$(echo $free | tr -d $UNIT )
if [ $free_space -le $ALERT ]; then
echo "Partition $partition ($mnt) running out of space ($free) on $(hostname) as on $(date)" |
mail -s "Alert: $mnt almost out of disk space on $(hostname) - $free" root
fi
done
It was initially taken and adapted from this blog post on nixCraft. Save this into a file in /etc/cron.hourly as root, modify the first 3 lines to suit your server and needs, and make the file executable. If you want to have it executed more often, save it as a script and create a regular cron job.
Note that you will need something providing the mail command, typically from the packages qmail-run or courier-mta.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
