Mountpoint monitoring script

Hi,

I am new to shell scripting. I prepared a very simple script to monitor mount points but not geting desired output.

df -h|awk -F' ' '{ if ($5 >= 80) print "CRITICAL\n" $NF " mount point has reached " $5;}'|sed -n '3,$p'

When I run above script in Sun solaris box it is executing perfectly fine.
But when I am running this script in Linux box i am not getting desired output.

Can you help please.

Many thanks in advance

Please post the output of the command df -h and the desired output.

output of

df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/vx/dsk/rootvol    4.3G   3.6G   684M    85%    /
/proc                    0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
fd                       0K     0K     0K     0%    /dev/fd
/dev/vx/dsk/var        2.0G   1.5G   392M    80%    /var
swap                   2.8G   112K   2.8G     1%    /var/run
swap                   3.8G  1021M   2.8G    27%    /tmp

desired output of

df -h|awk -F' ' '{ if ($5 >= 80) print "CRITICAL\n" $NF " mount point has reached " $5;}'|sed -n '3,$p'
CRITICAL
/ mount point has reached 85%
CRITICAL
/var mount point has reached 80%

And how is the output of df -h on the linux system?

output on linux

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-root
                      4.0G  627M  3.2G  17% /
tmpfs                 7.9G  624M  7.3G   8% /dev/shm
/dev/sda1             485M   77M  383M  17% /boot
/dev/mapper/rootvg-home
                      248M   70M  166M  30% /home
/dev/mapper/rootvg-opt
                      4.0G  1.4G  2.4G  38% /opt
/dev/mapper/rootvg-osmf
                      4.0G  582M  3.2G  16% /osmf/mgmt
/dev/mapper/rootvg-scheduler
                      217M  6.1M  200M   3% /osmf/mgmt/scheduler
/dev/mapper/rootvg-usr
                      5.0G  1.1G  3.7G  23% /usr
/dev/mapper/rootvg-var
                      4.0G  1.1G  2.7G  30% /var
none                  1.0G  430M  595M  42% /tmp

when i run script

df -h|awk -F' ' '{ if ($5 >= 10) print "CRITICAL\n" $NF " mount point has reached " $5;}'|sed -n '3,$p' 

getting below output

CRITICAL
/dev/shm mount point has reached 8%
CRITICAL
/boot mount point has reached 17%
CRITICAL
/tmp mount point has reached 42%

You may have to remove the "%" symbol form the %Use.
Try:

df -h |awk '{gsub("%","",$5);} $5 >= 10  print "CRITICAL\n" $NF " mount point has reached " $5;}'|sed -n '3,$p'

Try this:

df -h | awk 'NF==1{f=$1;getline;$0=f FS $0} int($5) >=80 {print "CRITICAL\n" $1 " has reach " $5}' file

Many Thanks it worked but i want to understand how it is working.
Could you please explain

Sure.

df -h | awk 'NF==1{f=$1;getline;$0=f FS $0} int($5) >=80 {print "CRITICAL\n" $1 " has reach " $5}' file

Explanation:

NF==1{f=$1;getline;$0=f FS $0} -> if the line has 1 field add the next line after the current line

int($5) >=80 {print "CRITICAL\n" $1 " has reach " $5} -> if field 5 >= 80 print the message

I hope this helps.

1 Like