Contents
1. Logwatch Install
① Install
1 |
# dnf install logwatch |
② Edit configuration file
1 2 3 4 5 6 7 8 9 10 |
# cat /usr/share/logwatch/default.conf/logwatch.conf >> /etc/logwatch/conf/logwatch.conf # vi /etc/logwatch/conf/logwatch.conf ●Per line 45 Insert "#" at the beginning of the "MailTo = root" line and set the email address you want to receive notifications under. #MailTo = root MailTo = <mail address> ●Per line 79 : Set the level of detail for log notifications #Detail = Low Detail = High |
1 |
# logwatch --output stdout |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
You will get the following message ################### 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 ------------------------ <abbreviation> -------------------- 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 ######################### |
1 |
# /etc/cron.daily/0logwatch |
2. Introduce disk usage check script
2.1 Script Creation
1 2 |
# cd /var/www/system # vi disk_capacity_check.sh |
Contents of disk_capacity_check.sh
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash #Designation of e-mail address to be notified MAIL="<mail address>" 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 |
1 |
# chmod 700 disk_capacity_check.sh |
2.2 Execution Confirmation
①Check current utilization
1 |
# df -h |
It appears as follows
1 2 3 4 5 6 7 8 |
Filesystem Size Used Avail Use% Mounted on devtmpfs 875M 0 875M 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/almalinux_alma-root 17G 6.0G 12G 36% / /dev/nvme0n1p1 1014M 257M 758M 26% /boot tmpfs 179M 0 179M 0% /run/user/1000 |
1 |
# dd if=/dev/zero of=dummyfile bs=1M count=9000 |
1 |
# df -h |
④Run disk space check script
1 |
# /var/www/system/disk_capacity_check.sh |
You will receive an email to the email address you set up with the body of the message as "Disk usage alert: 93 %".
⑤Delete the "dummyfile" you created.
1 |
# rm -f dummyfile |
1 2 |
# crontab -e 30 2 * * * /var/www/system/disk_capacity_check.sh |