大网数据广告活动
服务器运维问答

Notification for Disk-Space Shortage Issue in Server

· 52CE 我爱测

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, …

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-04-18)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。