Re: monitoring filesystem size (802 Views)
Reply
Frequent Advisor
rahul_rtns
Posts: 43
Registered: ‎11-23-2011
Message 1 of 9 (887 Views)

monitoring filesystem size

Hi,

 

Can anyone help to make a shell script that can monitor all the filesystems on my system and if filesystem space is more than 95%, then it should trigger a mail.

 

Regards,

Honored Contributor
Bill Hassell
Posts: 14,220
Registered: ‎05-29-2000
Message 3 of 9 (880 Views)

Re: monitoring filesystem size

There are two parts to this problem. One is to parse the output of bdf and the other is to prevent a mail storm.

 

The first part is tricky because bdf will split lines when the source name is too long. The simplest solution is to use the attached script and run it rather than bdf, like this:

 

    bdfmegs -qP 95

 

where -q removes the header and -P specifies only filesystems with more than 95% usage. There are numerous other options including selecting the volume groups to look at, selecting only local (not network) filesystems, etc.

 

The second part is to write your notificatioin script to not send email every time it is run. What sysadmins forget is that the email just keeps coming over and over when no one is there, holidays, weekends, etc. You'll need to write a script that looks for 95%+ filesystems, then checks to see if a notice has already been sent by looking at a file that has the last time an email was sent. If not, send the notice and save the current time (in Unix epoch seconds) in a small file. If a notice has been sent, compute the elapsed seconds since the last email was sent and it is less than 14,000 seconds (4 hours), exit with no email sent. Otherwise, send an email and update the small file with the current time.

 

The idea is to send only one email every 4 hours (14400 seconds) but be able to check the filesystems every 2 minutes so immediate notification is sent out. Now the script can be put into cron and run every 2 minutes without fear that more than 700 emails per day will be sent if the problem is not fixed.

Frequent Advisor
rahul_rtns
Posts: 43
Registered: ‎11-23-2011
Message 4 of 9 (844 Views)

Re: monitoring filesystem size

Hello,

 

I am using the below script to monitor the filesystem over consumption:

 

# RESULTS=$(bdf | awk '/^Filesystem/ {next};{if (NF==1) {line=$0;getline;gsub(" *"," ")};gsub(/%/,"");split(line$0,a," ");if (a[5]>90) {print line$0}}')

[ -z "${RESULTS}" ] || echo ${RESULTS} | mailx -r

 

But it is giving the filesystem which is in single line. The filesystem which are in split line are not getting grepped.

 

Regards,

Honored Contributor
Bill Hassell
Posts: 14,220
Registered: ‎05-29-2000
Message 5 of 9 (838 Views)

Re: monitoring filesystem size

[ Edited ]

Did you try bdfmegs? It eliminates all multi-line issues and also finds just the filesystems that are more than 90% full:

 

bdfmegs -q -P90

 

If you want to ignore network mount points from other servers, add the -l option for local-only.

Frequent Advisor
rahul_rtns
Posts: 43
Registered: ‎11-23-2011
Message 6 of 9 (813 Views)

Re: monitoring filesystem size

Hi,

 

Somehow due to security policies i am not able to use the bdfmegs in the server. However i am using the other thing for filesystem monitoring. But it is having a slight issue that i am not getting what is going wrong. The script i m using consists of :

 

bdf | awk '/^Filesystem/ {next};{if (NF==1) {line=$0;getline;gsub(" * "," ")};gsub(/%/,"");split(line$0,a," ");if (a[5]>95) {print line$0}}'

 

It is running successfully for split lines also. But for the very long device file names it is capturing the last largest fs name also with its below fs. For e.g. i m giving here an output of my bdf :

 

/dev/vg00/lvol4     524288  207352  314464   40% /home
/dev/vgbackupMS1/lv_backupMS1
                   614400000 214488301 374917470   36% /backupMS1
DevFS                    6       6       0  100% /dev/deviceFileSystem

 

The output for the above bdf script is coming as :

/dev/vgbackupMS1/lv_backupMS1DevFS                    6       6       0  100% /dev/deviceFileSystem

 

The other split lines it is capturing successfully. I am not getting what is going wrong.

 

Regards,

Acclaimed Contributor
Dennis Handly
Posts: 25,284
Registered: ‎03-06-2006
Message 7 of 9 (809 Views)

Re: monitoring filesystem size

[ Edited ]

>The script I'm using consists of :

bdf | awk '/^Filesystem/ {next};{if (NF==1) {line=$0;getline;gsub(" * "," ")};gsub(/%/,"");split(line$0,a," ");if    (a[5]>95) {print line$0}}'

 

That's your problem, you are putting it all on one line, instead of formatting it like a program.  ;-)

 

>I am not getting what is going wrong.

 

You aren't resetting line:

bdf | awk '
/^Filesystem/ {next}
{
if (NF == 1) {
   line=$0
   getline
   gsub(" * ", " ")
} else
   line=""  # No split line
gsub(/%/, "")
split(line$0, a, " ")
if (a[5] > 95) {print line$0}
}'

Frequent Advisor
rahul_rtns
Posts: 43
Registered: ‎11-23-2011
Message 8 of 9 (806 Views)

Re: monitoring filesystem size

>>bdf | awk '/^Filesystem/ {next};{if (NF==1) {line=$0;getline;gsub(" * "," ")};gsub(/%/,"");split(line$0,a," ");if (a[5]>95) {print line$0}}'

 

But the whole thing after awk is controlled by awk only. How can i split it.

 

Regards,


 

Acclaimed Contributor
Dennis Handly
Posts: 25,284
Registered: ‎03-06-2006
Message 9 of 9 (802 Views)

Re: monitoring filesystem size

>How can I split it?

 

Exactly as I showed you.

The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.