Computing.Net > Forums > Unix > Unix script help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Unix script help

Reply to Message Icon

Name: Devtakh
Date: March 30, 2004 at 14:35:11 Pacific
OS: HP-UX
CPU/Ram: 253.424KB
Comment:

Hi,
I want to write a script which basically monitors the amount of file usage (%) for a specific file system ,say "/mount1" for a amount of %,say 98%...When it reaches this %,it should generate a warning email to increase the disk space..
And this script should run once everyday at a specific time in unix.
Thanks for your help.

Best Regards,
Dev



Sponsored Link
Ads by Google

Response Number 1
Name: bryanpayne
Date: March 30, 2004 at 15:29:38 Pacific
Reply:

Here's one that I use for filesystem monitoring. You can modify it to do email alerts if you want.

Here is the config file called diskspace.tab:
# D I S K S P A C E . T A B
#
# Lookup file for the 'diskspace.sh' program.
# Format: <filesystem> <flag_percent> <alarm_percent>
#
/ 80 90
/var 30 40
/opt 90 97
/usr 90 95
/tmp 70 90
/stand 80 95
/home 80 95

---------END of DISKSPACE.TAB

Here is the script diskspace.sh:
# set -x
# D I S K S P A C E . S H
#
# 07/02/96
#
# Checks available disk space against a reference table,
# and flags the filesystems that are below their limit.
#

# 10/12/94 Original Version
# 03/06/96 Minor modifications for HP/UX 10.0
# 07/02/96 Fixes to handle multi-line bdf lines better


TABLE=/diskspace.tab
BOLD=`tput smso`
NORM=`tput rmso`

if [ ! -f $TABLE ]
then TABLE=./diskspace.tab
echo "Using Table file : "$TABLE
fi

echo "\n\n\n% Used\tWarn\tFilesystem Name\t\t\tCURRENT DISKSPACE STATUS"
echo---"

bdf | while read LINE
do
set x ${LINE}
if [ -n "$3" ] # If $3 is null, suspect multiline fs
then
shift 5
else
read LINE
set x ${LINE}
shift 4
fi

if [ -n "$1" -a "$1" != "used" ]
then
PERCENT=`echo $1 | tr -d '%'`
FILESYSTEM=$2

set x `grep "^${FILESYSTEM} " ${TABLE}` # tab aftr FS
if [ -z "$3" ]
then
continue
fi
MAX=$3
ALARM=$4
if [ -z "$4" ]
then
ALARM=100
fi
if [ ${PERCENT} -gt $MAX ]
then
HDR=${BOLD}
TRL=${NORM}
if [ ${PERCENT} -gt $ALARM ]
then
TRL="$TRL\t\t\t\t*** CRITICAL ***"
else
TRL="$TRL\t\t\t\t*** WARNING ***"
fi
else
HDR=""
TRL=""
fi

echo "${PERCENT}%\t(${MAX}%)\t${HDR}${FILESYSTEM}${TRL}"
fi
done

echo "\n"
exit 0
--------End of DISKSPACE.SH


0

Response Number 2
Name: Dlonra
Date: March 31, 2004 at 07:35:48 Pacific
Reply:

e.g. for /dev/hdb9
df -h |grep /dev/hdb9|awk '{ print $5 }'

or its mount point (/mnt/hdb9)
df -h |grep /mnt/hdb9 |awk '{ print $5 }'


0

Response Number 3
Name: Devtakh
Date: March 31, 2004 at 15:01:44 Pacific
Reply:

Hi Googly and Dlonra,

Thank you so much for you quick response and help.I will schedule it and will let you know what I get.
Once again.Thanks a ton!!

Regards,
Dev


0

Response Number 4
Name: Devtakh
Date: April 1, 2004 at 16:18:44 Pacific
Reply:

Hi Googly,
Thanks once again.I need some more help.
Since I am on the learning process,I find it a little tough to exactly understand the sequence/flow of this script.
Can you explain me a little bit about this config file.And I would appreciate if you can explain me what exactly is going on in each step.especially the lines like:

TABLE=/diskspace.tab
BOLD=`tput smso`
NORM=`tput rmso`


And how do I make it run this script daily for once using crontab...
Thank you so much..


Regards,
Dev


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Unix script help

basic unix scripting help www.computing.net/answers/unix/basic-unix-scripting-help/7686.html

help redoing unix script student db www.computing.net/answers/unix/help-redoing-unix-script-student-db/5151.html

UNIX script help please www.computing.net/answers/unix/unix-script-help-please/5517.html