Contents
1. Introduction of disk usage check scripts
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 #Specify email 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 Run confirmation
①Check your current usage
1 |
# df -h |
The following is displayed
1 2 3 4 5 6 |
Filesystem Size Used Avail Use% Mounted on udev 1.9G 0 1.9G 0% /dev tmpfs 391M 1.6M 390M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 19G 9.2G 8.6G 52% / dev/loop0 56M 56M 0 100% /snap/core18/2253 /dev/loop1 62M 62M 0 100% /snap/core20/1270 |
1 |
# dd if=/dev/zero of=dummyfile bs=1M count=8192 |
1 |
# df -h |
④Run a disk usage check script
1 |
# /opt/script/disk_capacity_check.sh |
You will receive an email to your email address with the text "Disk usage alert : 98%".
⑤Delete the "dummyfile" you have created
1 |
# rm dummyfile |
1 2 |
# crontab -e 30 2 * * * /opt/script/disk_capacity_check.sh |
2. Log analysis tool "Logwatch" installation
2.1 Install logwatch
1 |
# apt -y install logwatch |
2.2 Editing the logwatch configuration file
①Copy the default configuration file
1 |
# cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/ |
1 2 3 4 5 6 |
# vi /etc/logwatch/conf/logwatch.conf Line 54 MailTo =<your mailaddress> # < = Send email to Line 86 Detail = High # < = Log detail level(Low(0), Med(5), High(10) or Integer from 1 to 10) |
2.3 Create directory
There is no directory to use for caching, so create one.
1 |
# mkdir /var/cache/logwatch |
2.4 動作確認
If you install logwatch, it will be registered as a cron by default, so you will receive daily report emails
If you want to check now, you can do the following
1 |
# /etc/cron.daily/00logwatch |