Operating System - HP-UX
1834221 Members
2561 Online
110066 Solutions
New Discussion

Re: Shell script for checking filesystems

 
SOLVED
Go to solution
Matjaz Obstetar
Advisor

Shell script for checking filesystems

Hi,

I would like to check available space of each filesystem on my box with the shell script. This script I will run from the cron. When the available space decrease under the limit I would like to get the message in my mail box.
Could you help me and tell me where can I get a script with my requirements.

Thanks,

Matjaz
To sem jaz
7 REPLIES 7
Victor BERRIDGE
Honored Contributor

Re: Shell script for checking filesystems

Hi,
How about using Big Brother, it does what you want plus much more...
http://bb4.com/

Good luck
Victor
Vincenzo Restuccia
Honored Contributor

Re: Shell script for checking filesystems

#!/usr/bin/ksh
if [ $# -le 0 ] ;
then TRESHOLD=90 ;
else TRESHOLD=$1 ;
fi
# echo "Using Treshold = $TRESHOLD"
AAA_HOSTS='host1 host2 host3'
#> /tmp/report.log
#echo "Server\t\tFile System\t\tOccupation (>$TRESHOLD%)"
for h in $AAA_HOSTS ;
do
remsh $h -l root -n bdf | awk -v m=$h '{ if (NF==5) { d=substr($4,1,leng
th($4)-1) ; print m"@"$5"@"d } } { if (NF==6) { d=substr($5,1,length($5)-1) ; pr
int m"@"$6"@"d }}' | awk -F "@" -v t=$TRESHOLD '{ ORS="" ; if ($3>t) { print $1
; for (i=0;i<17-length($1);i++) print " " ; print $2 ; for (i=0;i<25-length($2);
i++) print " " ; print $3"%\n" } }'
done
Matjaz Obstetar
Advisor

Re: Shell script for checking filesystems

Hi,
This script will run on Virtual Vault, so 3-rd party software is irrelevant. The system is without Perl too.

regards,
Matjaz
To sem jaz
Printaporn_1
Esteemed Contributor

Re: Shell script for checking filesystems

try this

if [[ $(print $MOUNT | awk ' { print substr($1,1,1) } ') != '#' && $(print $
MOUNT | awk ' { print substr($1,1,1) } ') != '' ]] then
if bdf | egrep -v egrep | egrep $MOUNT 1>/dev/null 2>&1
then PERUSED=$(bdf $MOUNT | egrep -v [Uu]sed | awk {'print $5'})
PERUSED=${PERUSED%'%'}
if [[ $PERUSED -gt $PERCENTFLAG ]] then
print "${0##*/}: $MOUNT file system is $PERUSED% full"
echo "${0##*/}": $HOSTNAME $MOUNT file system is $PERUSED% full | mail
x -s "file system full" root
else
print "$MOUNT $PERCENTFLAG% OK..."
fi
else
print "file system $MOUNT does not exist"
fi

---------
config file like this

/home 80
/u101 90
/u102 90
/u103 90
/u104 90

---------
#fscheck config_file
it will checking with bdf , if exceed as specify in config file , it will mail to root.

---------
I cut from a part of a script , may be you need to modify
enjoy any little thing in my life
Juan José Muñoz
New Member

Re: Shell script for checking filesystems

try this

In ./scfs.dat, I put my static file systems, one fspath in each line, I don't want check them.


######################
# SCRIPT
######################

cd /usr/scripts
echo ""
echo " Sistemas de Archivo con Espacio Disponible < 25 MB o el 90% Ocupado"
echo "\n Muestra del: \c"
date +%d/%m/%y%t%X
bdf -l | grep -vf scfs.dat | sort -n +3 | awk -F " " '{ if ( NR==1 ) print " Espacio de Disco en MBytes\n\n Total Ocupado Disponible %usado Montado Dispositivo \n"; else if ( $4<25000 || $5>90 ) printf "%9.2f %9.2f %9.2f %3s %-10s %-26s\n", $2/1024, $3/1024, $4/1024, $5*1, $6, $1 }'
echo ""

##################
# FIN
##################
Nobody is perfect (Nobody)
Bill Hassell
Honored Contributor
Solution

Re: Shell script for checking filesystems

Try diskspace.ksh from:

ftp://contrib:9unsupp8@hprc.external.hp.com/sysadmin/cronjobs/

You can customize the script to set different limits for each filesystem.


Bill Hassell, sysadmin
Fred Martin_1
Valued Contributor

Re: Shell script for checking filesystems

I just posted this today in another message thread. See the message "What is the best way to configure performance alert", there's an attachment there that is a script file that I use.
fmartin@applicatorssales.com