Contents
1. Logwatch
①Install
1 |
# dnf install logwatch |
②Editing Configuration Files
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 8 |
●Per Line 45 Insert "#" at the beginning of the "MailTo = root" line and set the email address you want to receive notifications to the line below it. #MailTo = root MailTo = <mail address> ●Per Line 79 Set the level of detail for log notifications #Detail = Low Detail = High |
③Output Logwatch reports
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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
You will get the following message ################### Logwatch 7.4.3 (04/27/16) #################### Processing Initiated: Sat Aug 19 12:54:05 2023 Date Range Processed: yesterday ( 2023-Aug-18 ) Period is day. Detail Level of Output: 10 Type of Output/Format: stdout / text Logfiles for Host: Lepard ################################################################## --------------------- Amavisd-new Begin ------------------------ Redundant argument in sprintf at /usr/share/logwatch/scripts/services/amavis line 1338, <> line 23. ****** Summary ************************************************************************************* <中略> --------------------- Disk Space Begin ------------------------ Filesystem Size Used Avail Use% Mounted on devtmpfs 1.8G 0 1.8G 0% /dev /dev/mapper/ol-root 17G 7.8G 9.3G 46% / /dev/nvme0n1p1 1014M 282M 733M 28% /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.
Run the following command
1 |
# /etc/cron.daily/0logwatch |
2.Automatic DNS update script
Whenever the global IP changes, which happens when the network is disconnected or the router is disconnected and rebooted, we need to access Dynamic DNS to inform the user that the global IP has changed. We will install a script that will do this automatically.
This time, we assume that you will use Value Domain as your DNS service.
①Shell script for updating
Set DOMAINNAME= , PASSWORD= , HOSTNAME= to update a specific host such as login.example.com, HOSTNAME=login.
Content "dns_update.sh"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#/bin/bash #VARIABLES DOMAINNAME="example.com" PASSWORD="password" HOSTNAME="*" MYIP="" #External IP Acquisitions MYIP=`wget -q -O - "https://dyn.value-domain.com/cgi-bin/dyn.fcg?ip"` #SLEEP because cgi can become busy sleep 5 #update process wget -q -O - "https://dyn.value-domain.com/cgi-bin/dyn.fcg?d=$DOMAINNAME&p=$PASSWORD&h=$HOSTNAME&i=$MYIP" |
②Automatic Renewal Settings
Add the script to the crontab so that it is updated periodically
1 2 3 |
# crontab -e * 1 * * * /root/dns_update.sh |
3.Disk Usage Check Script
3.1 script
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 #Specify e-mail address for notification 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 |
3.2 Execution check
①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 1.8G 0 1.8G 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 1.8G 8.8M 1.8G 1% /run tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup /dev/mapper/ol-root 17G 7.8G 9.3G 46% / /dev/nvme0n1p1 1014M 282M 733M 28% /boot tmpfs 362M 0 362M 0% /run/user/1000 |
②Create a dummy file to have at least 80% utilization (in the example, it is named "dummyfile" and is about 9G).
1 |
# dd if=/dev/zero of=dummyfile bs=1M count=9000 |
③Reconfirmation
1 |
# df -h |
Confirmation that it is above 80%.
④Run Script
1 |
# /var/www/system/disk_capacity_check.sh |
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 : 98%".
⑤Delete the "dummyfile" you created.
1 |
# rm dummyfile |
⑥Periodic Execution Setting
1 2 |
# crontab -e 30 2 * * * /var/www/system/disk_capacity_check.sh |