Operating System - HP-UX
1827845 Members
1178 Online
109969 Solutions
New Discussion

Re: New to UNIX, need help with script

 
SOLVED
Go to solution
Jarheadatheart
Regular Advisor

New to UNIX, need help with script

Guru's, I am new to UNIX and attempting to learn a bit of scripting. Please see attached. The problem is that I do not know how to properly modify this script. It is to check filesystem usage, and e-mail when over 95% usage. However, the cron job has it running every 20 minutes, and it writes a new "emailfile" to /tmp everytime. How do I get it to run and ONLY create the file if something IS over 95% or possibly create the file everytime, but remove it afterwards??? Any help is appreciated.....
19 REPLIES 19
Stephan._1
Trusted Contributor

Re: New to UNIX, need help with script

Hi,
this will require more than a small change in the script. The whole concept in the script is at the moment to create the email file and check after it.


Line 33-35:
# Create the "emailfile"
echo "SEE THE FOLLOWING FILE: /tmp/"`date "+bdf%m%d%y%H"` > $emailfile
echo "" >> $emailfile

After a quick check there should be a file for every hour - or is it for every run?
Share what you know, learn what you don't.
James R. Ferguson
Acclaimed Contributor

Re: New to UNIX, need help with script

Hi:

First, please post your attachment as a TEXT file and not a Microsoft Word document.

...JRF...
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

SVO, it is every run..... not just every hour

My apologies, here it is again in Text.
James R. Ferguson
Acclaimed Contributor

Re: New to UNIX, need help with script

Hi:

The script will need some work. You might be better served by using and studying one that meets your objectives. Bill Hassell has one as an attachment in this thread :

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

Regards!

...JRF...
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

Thanks James, that is incredibly helpful.... Gonna take be a bit to get through it all, but juding by the description, this will work wonderfully.
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

James,
I have been trying this all day. I get error: /usr/local/bin/diskspace.sh[391]: /home: Syntax error

IF I DON'T clear out all temp files used located on /var/tmp/diskspace

If I do clear them out, I don't get the syntax error but either way I DON'T get the e-mail notification.

Thoughts?
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

Upon further review, it is supposed to error out IF that filesystem has already been marked.

However, the sendmail syntax still won't send the mail...... and the debug doesn't show anything.
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

attached is the debug
James R. Ferguson
Acclaimed Contributor
Solution

Re: New to UNIX, need help with script

Hi (again):

If you don't have any HFS filesystems then delete the 'hfs' token from the '/etc/diskspace.conf' file that you should have created (see the internal instructions).

Then run the script like:

# ./diskspace.sh -e"jarheadatheart@us.org"

This gives me alerts, BUT upon rerunning, I see the behavior you noted:

...[390]:LASTVALUE + INCR: The specified number is not valid for this command.

The key appears to be to make sure that you have a 'diskspace.conf' file that has mountpoints with maximum and minimums defined, like:

/usr 90 2

...but not:

/usr 90

...despite what the documentation might suggest.

For example, this works only the first time and fails thereafter:

vxfs
25 1
/patches 26

...but this fixes the problem:

vxfs
25 1
/patches 26 1

Regards!

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

Re: New to UNIX, need help with script

Hi (again):

A better solution to your problem may be to add a one-line patch at line-388:

...
385 # Been there before but have we exceeded to INCR value? Note: we may
386 # be at 99% so the script will repeat.
387
388 [ -z "${INCR}" ] && INCR=${DEFINCR} #...patch...
389 LASTVALUE=$(echo $BEENTHERE | awk '{print $2}')
390 if [ $((LASTVALUE + INCR)) -le $PERCENT ]
...

This resets the default increment if it isn't defined. Now you can follow the documentation for the 'diskspace.conf' layout exactly.

Regards!

...JRF...
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

James, one last thing. How would I set that to a cronjob? I can't set the cron to run as
/usr/local/bin/diskspace.sh -e "me@me.org"

Can I?
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

I apologize for my ignorance. I am VERY new to UNIX.
James R. Ferguson
Acclaimed Contributor

Re: New to UNIX, need help with script

Hi (again):

> How would I set that to a cronjob? I can't set the cron to run as
/usr/local/bin/diskspace.sh -e "me@me.org"

For example:

00,10,20,30,40,50 * * * * /usr/local/bin/diskspace.sh -e"me@me.org"

...would run the process every 10-minutes after every hour on every day of the week, etc.
There is more information in the 'crontab' manpages. You're doing fine :-)

Regards!

...JRF...
Tom Ward_1
Honored Contributor

Re: New to UNIX, need help with script

You can use
/usr/local/bin/diskspace.sh -e "me@me.org"
as your command in the crontab entry.

If your scirpt has any output you may want to add
> /dev/null
to the end of the command so you don't get mailed from cron every time it runs.
If there is error output cron will still mail that.
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

Thanks... I have got the times/dates portion of cron down I think! HAHAHA!

So I can in fact run it like that. ok.

And the >/dev/null will make it only send me an e-mail if the script finds something?
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

would the entry be >>/dev/null 2>&1 or just >>/dev/null
James R. Ferguson
Acclaimed Contributor

Re: New to UNIX, need help with script

Hi:

> And the >/dev/null will make it only send me an e-mail if the script finds something?

You don't need to add that in this case. By default, 'cron' creates mail and sends it to the user's crontask _IF_ either STDOUT and/or STDERR has not been redirected (to a file).

Regards!

...JRF...
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

ah. Ok, thanks James!
Jarheadatheart
Regular Advisor

Re: New to UNIX, need help with script

Thanks a lot guys!