Languages and Scripting
cancel
Showing results for 
Search instead for 
Did you mean: 

script to alert when File system has reached > 87%

 
SOLVED
Go to solution
Highlighted
NDO
Super Advisor

script to alert when File system has reached > 87%

Hi All!

I know that is a topic that has been here in the forums lots of times, but I´m facing a different scenario. The file system used in the server is veritas, so the format is :
"/dev/vx/dsk/dgrac/data05
104791936 95884935 8350314 92% /data05"

which is different from the O.S. file systems which are:
"/dev/vg00/lvol1 2097152 349280 1734264 17% /stand"

I´m still learning writing scripts, but I´ve not figured out yet how to have an output that will show me if a partcular F.S. either on normal layout or on the veritas format!

So please can you help?

Regards

F.R.
8 REPLIES 8
Highlighted
James R. Ferguson
Acclaimed Contributor

Re: script to alert when File system has reached > 87%

Hi:

The fields are equivalent, merely split into two lines due to the length of the device file name.

See this thread for more explanation and solutions:

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1369609

Regards!

...JRF...
Highlighted
NDO
Super Advisor

Re: script to alert when File system has reached > 87%

Hi

Sorry James, But I dont know where to incorporate your suggestion (bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ");print line$0} else {print}}') into the script I have which:
bdf | awk '{ if ( $5 > "90%" ) print $0 }' | mailx -r root@node0.com fretagi@abcd.com

Can you be more specific? Or help?

Regards

F.R.
Highlighted
James R. Ferguson
Acclaimed Contributor
Solution

Re: script to alert when File system has reached > 87%

Hi (again):

# bdf | awk '{if (NF==1) {line=$0;getline;sub(" *"," ")};split(line$0,a," ");if (a[5]>90) {print line$0}}' | mailx -r root@node0.com fretagi@abcd.com

The idea is that if two lines are required to report a filesystem, the lines are joined together. We then split the line into fields and test accordingly.

Regards!

...JRF...
Highlighted
James R. Ferguson
Acclaimed Contributor

Re: script to alert when File system has reached > 87%

Hi (again):

Oops, posted too fast. I'm sure you don't want mail generated unless the alert level is actually exceeded. Do something like:

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

[ -z "${RESULTS} ] || echo ${RESULTS} | mailx -r root@node0.com fretagi@abcd.com

The change above skips the header of 'bdf' and collects any output in a variable called 'RESULTS'. Only if that variable isn't empty do we send mail.

Regards!

...JRF...
Highlighted
NDO
Super Advisor

Re: script to alert when File system has reached > 87%

Hi

James! Thanks a lot, your first script worked great, but the second there is an error expecting " on this line:
[ -z "${RESULTS} ] || echo ${RESULTS} | mailx -r


I´m going to put that on a cron, to run 3 times a day, that will be enough for the oracle dba and myself.


regards

F.R.
Highlighted
James R. Ferguson
Acclaimed Contributor

Re: script to alert when File system has reached > 87%

Hi (again):

I missed a double-quote:

[ -z "${RESULTS}" ] || echo ${RESULTS} | mailx -r root@node0.com fretagi@abcd.com

Regards!

...JRF...
Highlighted
James R. Ferguson
Acclaimed Contributor

Re: script to alert when File system has reached > 87%

Hi:

And one last correction for the last stupid mistake. We should strip the "%" from the field before comparing for correctness in all cases. Hence:

# 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 root@node0.com fretagi@abcd.com

You could also leverage Bill's script in the original post I cited. Read the documentation that he has in the beginning of his attached script.

Regards!

...JRF...
Highlighted
NDO
Super Advisor

Re: script to alert when File system has reached > 87%

Hi James!

Thanks a lot for your help, I guess I need to learn shell script and awk to get to your level of programming.There so much stuff on the net so I dont know where to start

regards

F.R.