1. Logwatch
① Install
# vi /etc/logwatch/conf/logwatch.conf
Insert "#" at the beginning of the "MailTo = root" line and set the email address you want
toreceive notifications to the line below it.
#MailTo = root
MailTo = [Email Address]
●Per line 79 : Set the level of detail for log notifications
#Detail = Low
Detail = High
③ Output Logwatch reports
################### Logwatch 7.6 (01/22/22) ####################
Processing Initiated: Fri May 13 09:41:46 2022
Date Range Processed: yesterday
( 2022-May-12 )
Period is day.
Detail Level of Output: 10
Type of Output/Format: stdout / text
Logfiles for Host: fedora
###########################################################
--------------------- Amavisd-new Begin ------------------------
<中略>
-------------------- Disk Space Begin ------------------------
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/fedora_fedora-root 15G 4.4G 11G 30% /
/dev/nvme0n1p1 1014M 245M 770M 25% /boot
---------------------- Disk Space End -------------------------
###################### Logwatch End #########################
2. Introduce disk usage check script
2.1 Scripting
# vi disk_capacity_check.sh
#!/bin/bash
#Designation of e-mail address to be notified
MAIL="<your mailaddress> "
DVAL=`/bin/df / | /usr/bin/tail -1 | /bin/sed 's/^.* \([0-9]*\)%.*$/\1/'`
if [ $DVAL -gt 80 ]; then
echo "Disk usage alert: $DVAL %" | mail -s "Disk Space Alert in `hostname`" $MAIL
fi
2.2 Execution Confirmation
①Check current usage
It appears as follows
devtmpfs 873M 0 873M 0% /dev
tmpfs 893M 0 893M 0% /dev/shm
tmpfs 893M 8.8M 884M 1% /run
tmpfs 893M 0 893M 0% /sys/fs/cgroup
/dev/mapper/rl_rocky-root 17G 6.2G 11G 38% /
/dev/nvme0n1p2 1014M 208M 807M 21% /boot
/dev/nvme0n1p1 599M 5.8M 594M 1% /boot/efi
tmpfs 179M 0 179M 0% /run/user/1000
②Create a dummy file to have at least 80% utilization (in the example, it is named "dummyfile" and is about 8G).
# dd if=/dev/zero of=dummyfile bs=1M count=8000
③Re-confirmation
Confirmation that it is at least 80%.
④Run disk space check script
You will receive an e-mail to the e-mail address you have set up with the body of the message as "Disk usage alert : 86%".
⑤Delete the "dummyfile" you created.
⑥Periodic Execution Setting
30 2 * * * /var/www/system/disk_capacity_check.sh