Contents [Open]
Logwatch
①Install
1 |
# dnf install logwatch |
②Edit configuration file
1 2 |
# cat /usr/share/logwatch/default.conf/logwatch.conf >> /etc/logwatch/conf/logwatch.conf # vi /etc/logwatch/conf/logwatch.conf |
1 2 3 4 5 6 7 |
●Per line 51 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 84 : 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
################### Logwatch 7.5.5 (01/22/21) #################### Processing Initiated: Sun Jan 8 16:48:56 2023 Date Range Processed: yesterday ( 2023-Jan-07 ) Period is day. Detail Level of Output: 10 Type of Output/Format: stdout / text Logfiles for Host: Lepard ################################################################## --------------------- Amavisd-new Begin ------------------------ ****** Summary ************************************************************************************* 2 Total messages scanned ------------------ 100.00% 1.885K Total bytes scanned 1,930 ======== ================================================== 2 Passed ---------------------------------- 100.00% 2 Clean passed 100.00% ======== ================================================== 2 Ham ------------------------------------- 100.00% 2 Clean passed 100.00% ======== ================================================== 2 SpamAssassin bypassed Amavis Startup Amavis /usr/sbin/amavisd Version 2.12.2 (20211013) Antivirus scanners Primary internal ClamAV-clamd Secondary ClamAV-clamscan /usr/bin/clamscan Code, modules and external programs Not found .lz4 tried: lz4c -d .rar tried: unrar, rar Decoders None .lz4 tried: unknown SpamAssassin plugins ---------------------- Amavisd-new End ------------------------- --------------------- Kernel Audit Begin ------------------------ <omission > --------------------- Disk Space Begin ------------------------ Filesystem Size Used Avail Use% Mounted on /dev/mapper/rl-root 17G 5.0G 13G 30% / /dev/nvme0n1p1 1014M 270M 745M 27% /boot ---------------------- Disk Space End ------------------------- --------------------- lm_sensors output Begin ------------------------ No sensors found! Make sure you loaded all the kernel drivers you need. Try sensors-detect to find out which these are. ---------------------- lm_sensors output 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="<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 |
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 9 10 |
Filesystem Size Used Avail Use% Mounted on devtmpfs 856M 0 856M 0% /dev tmpfs 875M 0 875M 0% /dev/shm tmpfs 350M 9.6M 341M 3% /run /dev/mapper/rl-root 17G 5.0G 13G 30% / /dev/loop0 64M 64M 0 100% /var/lib/snapd/snap/core20/1695 /dev/loop2 48M 48M 0 100% /var/lib/snapd/snap/snapd/17336 /dev/loop1 45M 45M 0 100% /var/lib/snapd/snap/certbot/2511 /dev/nvme0n1p1 1014M 270M 745M 27% /boot tmpfs 175M 4.0K 175M 1% /run/user/1000 |
1 |
# dd if=/dev/zero of=dummyfile bs=1M count=9000 |
1 |
# df -h |
1 |
# /var/www/system/disk_capacity_check.sh |
⑤Delete "dummyfile"
1 |
# rm dummyfile |
⑥Periodic Execution Setting
1 2 |
# crontab -e 30 2 * * * /var/www/system/disk_capacity_check.sh |