Shell script for File System monitoring |
In a database environment or any server environment we need to monitor space usage of file system.
Below shown is the usage of file system for my environment.
[grid@rac1 ~]$ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 1.4G 0 1.4G 0% /dev tmpfs 1.4G 0 1.4G 0% /dev/shm tmpfs 1.4G 9.5M 1.4G 1% /run tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup /dev/mapper/ol-root 30G 27G 3.4G 89% / /dev/sda1 2.0G 234M 1.8G 12% /boot SW 932G 568G 364G 61% /media/sf_SW tmpfs 271M 32K 271M 1% /run/user/54322There are many ways to monitor the filesystem either using tools or scripts. Here we are going to write a schell script to monitor the file system. This script should be writen by DBA or OS administrator. The script is schedule to run for every 10 mins. [grid@rac1 ~]$ cat check_FS.sh ####################################################################### # # check_FS.sh # # Script for checking mountpoint space by passing threshold limit as argument # # TesDBAcadmy.com # ######################################################################### clear echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" echo "Below file system exceeds $1%" echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" for i in `df -P|grep -v "File"|tr -s " " "~"|cut -d"~" -f5|tr -s "%" " "` do if [ $i -gt $1 ] then x=`df -h|grep $i%` echo $x > /home/grid/check_FS.log fi done echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"Here our threshold value is 10 and can be dynamically passed as parameter to the schell script. The filesystem which exceeds the threshold will be stored under /home/grid/check_FS.log. [grid@rac1 ~]$ ./check_FS.sh 10 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Below file system exceeds 10% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /dev/mapper/ol-root 30G 27G 3.4G 89% / /dev/sda1 2.0G 234M 1.8G 12% /boot SW 932G 568G 364G 61% /media/sf_SW ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~In cron you can specify as shown Below. [grid@rac1 ~]$ crontab -l */10 * * * * /home/grid/check_FS.sh 10 > /dev/null 2>&1 « Previous Next Topic » (Listener and Database Monitoring) |