1754303 Members
3154 Online
108813 Solutions
New Discussion юеВ

Require assistance

 
SOLVED
Go to solution
cse.ashish
Occasional Contributor

Require assistance

Hi,
I am trying to automate a process.
Whenever the file system in HP-UX box got more than 85% I need to send a mail to my email-ID with the percentage of that volume and name of that volume.
Note, I don't want to get all the file systems info. I want only those whih are at 85% or more.

Also, can anybuddy help in finding out how to compare percentages in Shell Script.
e.g I wana to compare whether 45% is gt 65% or not.
Nothing is impossible in this world cauz impossible itself says that "I M POSSIBLE"
7 REPLIES 7
spex
Honored Contributor

Re: Require assistance

Hello,

Schedule the following to run every 5 minutes or so...

# cat check_filesystem_usage.sh
#!/usr/bin/sh

typeset -i MAXPCT=85
typeset -i TIMEOUT=1 # number of days to retain LOCKFILE
BDFMEGS=/path/to/bdfmegs.sh
TEMPFILE=/tmp/check_filesystem_usage.${$}.tmp
LOCKFILE=/tmp/check_filesystem_usage.lck

# rm ${LOCKFILE} if mtime > ${TIMEOUT}, so that duplicate reports will be generated, on occasion
find ${LOCKFILE} -type f -mtime +${TIMEOUT} -print | xargs rm -f 2> /dev/null
[ ! -f ${LOCKFILE} ] && touch ${LOCKFILE}

trap "[ -f ${TEMPFILE} ] && rm -f ${TEMPFILE}" 0 1 2 3 15
${BDFMEGS} -qglP ${MAXPCT} | grep -v '^$' > ${TEMPFILE}

if [ -s ${TEMPFILE} ]
then
$(grep -q -v -f ${LOCKFILE} ${TEMPFILE}) && \
{ grep -v -f ${LOCKFILE} ${TEMPFILE} >> ${LOCKFILE}
mailx -m -s "WARNING! FILESYSTEM(S) OVER ${MAXPCT}% FULL!" your@email.addr << EOF
File-System Gbytes Used Avail %Used Mounted on
$(cat ${TEMPFILE})

Remember to delete ${LOCKFILE} after freeing up space!
EOF
}
# exit with rc of 1 if any filesystems with utilization > ${MAXPCT} were returned
exit 1
fi

# otherwise, exit with rc of 0
exit 0

This script relies on version 4.5 of Bill Hassell's bdfmegs script, available at the bottom of this thread:

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

PCS
spex
Honored Contributor

Re: Require assistance

> Also, can anybuddy help in finding out how
> to compare percentages in Shell Script.
> e.g I wana to compare whether 45% is gt 65%
> or not.

I assume you are using the POSIX or Korn shell. Use variable substitution to strip the trailing '%':

$ A='45%'
$ B='65%'
$ echo ${A} ${B}
45% 65%
$ A=${A%%\%}
$ B=${B%%\%}
$ echo ${A} ${B}
45 65
$ [ ${A} -lt ${B} ] && echo true || echo false
true

PCS
cse.ashish
Occasional Contributor

Re: Require assistance

Thanks Spex.
Seems to be helpfull to me.
Will try to use the same and then check whether working or not. :)
And yes, I am using Korn Shell.
Nothing is impossible in this world cauz impossible itself says that "I M POSSIBLE"
Bill Hassell
Honored Contributor
Solution

Re: Require assistance

One of the biggest problems with space monitoring scripts is that they will create a massive storm of messages (every 5 minutes for example) until the problem is fixed. On the weekend or late at night, if no one is available to fix the problem, you'll have dozens of messages to delete from your cell phone, pager, or email.

The attached script will do everything for you including preventing a storm of messages. It can notify one or several people by email, log the condition into syslog.log or send a notice to OpenView's Operations Center (or all three if desired). You set a default percentage level for all filesystems, perhaps 85%, and then customize specific filesystems at a different level such as 92%. And you also specify the growth value which is the amount that the filesystem must grow beyond the limit before another message is generated. This is the key to avoiding email storms. You can also exclude filesystems from being monitored by specifying 101% as the limit.

To use, store the attached script in your sysadmin script directory, then create the config file /etc/diskspace.conf file and create the two required lines: filesystem types and default percentages:

hfs vxfs
92 2

This specifies that only vxfs and hfs will be monitored and thatt the default for all filesystems is 92% or more and 2% growth for more messages. Then add additional lines for special handling such as:

/tmp 85 5
/extra 101 100
/usr 85 3

and that's it. You can test the output of the script without sending any notifications by leaving off any parameters. In that case, the output goes directly to stdout.

Now add the script to crontab to run as often as you'd like (I would not run it more than once every 5 or 10 minutes) and specify the options for notifications:

* 0,10,20,30,40,50 * * * /usr/local/sysadmin/diskspace.sh -e diskspace.sh@mysystem -s warn

Note the use of the script's name as the address. In /etc/mail/aliases, I create an alias for every script and then add the appropriate email addresses to the alias. That way, I don't have to code anything into the script or change crontab to send to different email addresses.


Bill Hassell, sysadmin
cse.ashish
Occasional Contributor

Re: Require assistance

Thanks a lot Bill. I think my problem is resolved now. I am able to run the script by sum modifications (of course not in the logic).

One more thing, I am looking for a command which can filter out all the files which have been created or modified 15 days or before from the today's date.
Can you or any buddy else help me out in this too.
Nothing is impossible in this world cauz impossible itself says that "I M POSSIBLE"
Yogeeraj_1
Honored Contributor

Re: Require assistance

hi Ashish,

> One more thing, I am looking for a command which can filter out all the files which have been created or modified 15 days or before from the today's date.
Can you or any buddy else help me out in this too.

If this is a new question, i would be preferrable that you create a new post.

Anyway,

try this solution:
mfifteendaysEarlier='0705240000'
mtoday='0706072359'

touch -t $mtoday /tmp/start
touch -t $mfifteendaysEarlier /tmp/finish
find . -xdev -type f -newer /tmp/start -a ! -newer /tmp/finish | xargs rm

(this is based on one solution that JRF provided once)

hope this helps!
kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
cse.ashish
Occasional Contributor

Re: Require assistance

Thanks Yogeeraj,

I have started a new thread for the same question. Link is as below.
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1134277

Regards,
Ashish
Nothing is impossible in this world cauz impossible itself says that "I M POSSIBLE"