Logwatch
①Install
1 |
# dnf install logwatch |
②Edit configuration file
1 2 3 4 5 6 7 8 9 |
# cat /usr/share/logwatch/default.conf/logwatch.conf >> /etc/logwatch/conf/logwatch.conf # vi /etc/logwatch/conf/logwatch.conf ●Line 53 : Set "MailTo = root" as a comment and set the email address you want to receive notifications to the line below it. #MailTo = root MailTo = [Mail address] ●Per line 86 : Set the level of detail for log notifications #Detail = Low Detail = High |
③Output Logwatch reports
1 |
# logwatch --output stdout |
It will appear as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
################### Logwatch 7.8 (01/22/23) #################### Processing Initiated: Thu Apr 27 11:24:18 2023 Date Range Processed: yesterday ( 2023-Apr-26 ) Period is day. Detail Level of Output: 10 Type of Output/Format: stdout / text Logfiles for Host: Lepard ################################################################## --------------------- Amavisd-new Begin ------------------------ Can't locate subs.pm in @INC (you may need to install the subs module) (@INC co ntains: /usr/share/logwatch/lib /usr/local/lib64/perl5/5.36 /usr/local/share/per l5/5.36 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/per l5 /usr/share/perl5) at /usr/share/logwatch/scripts/services/amavis line 83. BEGIN failed--compilation aborted at /usr/share/logwatch/scripts/services/amavi s line 83. ---------------------- Amavisd-new End ------------------------- -----------omission--------- **Unmatched Entries** Binding to IPv6 address not available since kernel does not support IPv6.: 12 Time(s) No hostname configured, using default hostname.: 1 Time(s) ---------------------- Systemd End ------------------------- --------------------- Disk Space Begin ------------------------ Filesystem Size Used Avail Use% Mounted on /dev/mapper/fedora-root 15G 4.3G 11G 29% / /dev/nvme0n1p2 960M 218M 743M 23% /boot ---------------------- Disk Space End ------------------------- ###################### Logwatch End ######################### |
④Test to see if the report arrives at the address you set. Check if you receive a log report email like the one above.
1 |
# /etc/cron.daily/0logwatch |
Introduce disk usage check script
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 Execution Confirmation
①Check current usage rates
1 |
# df -h |
It appears as follows
1 2 3 4 5 6 7 8 |
Filesystem Size Used Avail Use% Mounted on devtmpfs 4.0M 0 4.0M 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 1.6G 1.5M 1.6G 1% /run /dev/mapper/fedora-root 15G 2.8G 13G 19% / tmpfs 3.9G 0 3.9G 0% /tmp /dev/nvme0n1p2 960M 280M 681M 30% /boot tmpfs 790M 0 790M 0% /run/user/1000 |
②Create a dummy file to achieve at least 80% utilization
1 |
# dd if=/dev/zero of=dummyfile bs=1M count=10000 |
➂Run check scripts
1 |
# /var/www/system/disk_capacity_check.sh |
You will receive an email to the email address you have set up, stating something like "Disk usage alert: 84%".
④Delete "dummyfile"
1 |
# rm dummyfile |
⑤Periodic Execution Setting
1 2 |
# crontab -e 30 2 * * * /var/www/system/disk_capacity_check.sh |