Operating System - Linux
1752598 Members
5481 Online
108788 Solutions
New Discussion юеВ

write a script to check the usage of a file system

 
Bishooo
Advisor

write a script to check the usage of a file system

Hello Gents,

I need to write a script to check the usage of a file system and send out a mail if the filesystem is more than 95%.

Could you please help me to write this script?



Bishooo
14 REPLIES 14
Fabio Ettore
Honored Contributor

Re: write a script to check the usage of a file system

Hi,

check the following thread where I attached a script to do what you are looking for:

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

You can manage the variable SYSMAX, in your example you can change to

SYSMAX=95

So if there a filesystem taking over 95% then you will receive a mail (to ). Anyway the check is done when starting the script, so you can schedule it every day by cron to start.

HTH.

Best regards,
Fabio
WISH? IMPROVEMENT!
inventsekar_1
Respected Contributor

Re: write a script to check the usage of a file system

this is i found in "favorite sysadmin scripts you always keep around (3)"
-------------------------------------------

This is another file system size checking script using bdf.

File system is >= 90% - email root.
File system is > 95% - page somebody.

It will work when lvol names are large and running bdf drops the "kbytes used" etc data to the next line.

-------------------------------------------
u need to check the format and do some modifications and assign points to ur 8 responses (from ur profile:I have assigned points to 0 of 8 responses to my questions.)
Be Tomorrow, Today.
Bishooo
Advisor

Re: write a script to check the usage of a file system

Sorry I didn't get the answer clearly.
I'm new to HP-UX so please explain to me...
I didn't know what should I write in the script!

Sorrt :$
Bishooo
Advisor

Re: write a script to check the usage of a file system

Sorry I didnt get it clearly...
I'm new to hpux specialy the scripting so please I didn't know what should I write in the script?


Sorry :$
Fabio Ettore
Honored Contributor

Re: write a script to check the usage of a file system

Hi,

I will answer about my post to explain better what you have to do:

- go in thread indicated by me;
- save the attachment of the my post under /tmp on HP-UX system;
- rename it to something familiar and give execute permission:

mv .sh FSUSAGE.sh
chmod 755 FSUSAGE.sh
./FSUSAGE.sh

For each filesystem taking over 85% the script will send a mail to .

Of course you have to change to a mail address and if you want then can change the variable SYSMAX to 95 in order to have the mail when filesystems taking over 95%.

I hope that clarifies better for you.

Best regards,
Fabio
WISH? IMPROVEMENT!
Bishooo
Advisor

Re: write a script to check the usage of a file system

#cd /tmp
then
I create fs.sh and I add:
SYSMAX=85
for MNTPT in `cat /etc/mnttab | awk '{print $2}'|grep -v net | grep -v home`
do
FILESYS=`bdf $MNTPT | grep -v avail | awk '{print $5}'| tr -d "%"`
if [ $FILESYS -gt $SYSMAX ]
then
echo "WARNING: $MNTPT File System is using $FILESYS% of diskspace allocated " | elm -s "WARNING! There is a filesystem near full!"
fi
done

Then
#mv fs.sh FSUSAGE.sh
# chmod 755 FSUSAGE.sh
#./FSUSAGE.sh
./FSUSAGE.sh[2]: Syntax error at line 8 : `newline or ;' is not expected.
James R. Ferguson
Acclaimed Contributor

Re: write a script to check the usage of a file system

Hi Bishoo:

The script is missing several things. This variation will work (at least syntactically):

#!/usr/bin/sh
SYSMAX=85
for MNTPT in `cat /etc/mnttab | awk '{print $2}'|grep -v net | grep -v home`
do
FILESYS=`bdf $MNTPT | grep -v avail | awk '{print $5}'| tr -d "%"`
if [ $FILESYS -gt $SYSMAX ]
then
echo "WARNING: $MNTPT File System is using $FILESYS% of diskspace allocated " |
elm -s "WARNING! There is a filesystem near full!" root
fi
done

...Note that I added an interpreter line at the very beginning that tells exactly what (shell) interpreter we want to use. We will use the standard HP-UX Posix shell.

You missed customizing your mail account. I've substituted 'root' for "". The bare angle brackets sugguested a redirection to the shell and were syntactically invalid there.

Replace your current version with this one or make the changes yourself. Be sure to grant execute permissions if necessary, again.

If you are new to shell scripting, have a look at the "Shells: User's Guide". I suggest that you use the POSIX shell since this is the default for HP-UX. I would urge you not to use 'csh'. It is very feature-poor.

http://docs.hp.com/en/B2355-90046/B2355-90046.pdf

Regards!

...JRF..

Fabio Ettore
Honored Contributor

Re: write a script to check the usage of a file system

In addition to the post by James, consider that

echo "WARNING: $MNTPT File System is using $FILESYS% of diskspace allocated " | elm -s "WARNING! There is a filesystem near full!"

has to be on a unique line (even if you see two lines in my post).

Best regards,
Fabio
WISH? IMPROVEMENT!
harry_7
Frequent Advisor

Re: write a script to check the usage of a file system

Hi,

Please find attached a script.

You have to create a mailing list for email and pager. Hopefully this will help you.

Regards.

Harrry.