Contents
1. Introduce disk usage check script
1.1 Script Creation
| 1 2 | # cd /opt/script/ # 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 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 | 
1.2 Execution Confirmation
①Check current usage
| 1 | # df -h | 
It appears as follows
| 1 2 3 4 5 6 7 | Filesystem                         Size  Used Avail Use% Mounted on tmpfs                              196M  1.1M  195M   1% /run /dev/mapper/ubuntu--vg-ubuntu--lv   12G  8.3G  2.4G  78% / tmpfs                              980M     0  980M   0% /dev/shm tmpfs                              5.0M     0  5.0M   0% /run/lock /dev/sda2                          2.0G  146M  1.7G   8% /boot tmpfs                              196M  4.0K  196M   1% /run/user/1000 | 
Create a dummy file so that it is 80% or more (in this case, create about 1G).
| 1 | # dd if=/dev/zero of=dummyfile bs=1M count=1000 | 
③again Confirmation
| 1 | # df -h | 
Confirmation that it is above 80%.
④Run disk space check script
| 1 | # /opt/script/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: 87 %".
⑤Delete the "dummyfile" you created.
| 1 | # rm dummyfile | 
⑥Periodic Execution Setting
| 1 2 | # crontab -e 30 2 * * * /opt/script/disk_capacity_check.sh | 
Ads are being blocked.
2. Log analysis tool Logwatch installed
2.1 Install logwatch
| 1 | # apt -y install logwatch | 
2.2 Edit logwatch configuration file
①Copy the default configuration file
| 1 | # cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/ | 
②Change email address, etc.
| 1 2 3 4 5 | # vi /etc/logwatch/conf/logwatch.conf Line 52 MailTo =<your mailaddress> # < = Mailing address Line 84 Detail = High | 
2.3 Creating Directories
There is no directory used by the cache, so create one.
| 1 | # mkdir /var/cache/logwatch | 
2.4 operation check
When logwatch is installed, cron is registered by default, so you will receive daily report emails.
If you want to check it immediately, do the following
| 1 | # /etc/cron.daily/00logwatch | 
Ads are being blocked.
      
