Monitoring Script - filesystem

Hi all,

I got an error when running this script (from BigAdmin community)
the error is

test: argument expected

my server version is
SunOS XXX 5.8 Generic_117350-46 sun4u sparc SUNW,Sun-Fire-V890

any idea on it?

#! /usr/bin/ksh

### 
### This script can be run from cron to periodically check 
### filesystems for low disk space and send an e-mail.
###
###  Variables: 
###     MAXSIZE = percentage filesystem must be full before notification
###     NOTIFY = email address to notify when file system reaches MAXSIZE
###

### Configurable variables here
MAXSIZE=90
NOTIFY=xxx@domain.com
HOSTNAME=`hostname`

# Add filesystems you wish to skip from checking
FSLIST=`df -k | grep -v "cdrom" | grep -v "mnt"  | awk '{ \
                fssize=substr($5,1,index($5,"%")-1)
                if (int(fssize) > int(maxsize)) {
                        print $6":"fssize
                }
        }' maxsize=$MAXSIZE`

### Were there any fs to report?
if [ -z $FSLIST ]; then
	echo "There were no reportable filesystems."
	exit 0
fi

### Mail out the list if there is one
for fs in $FSLIST
do
        FS=`echo $fs | cut -f1 -d:`
        SIZE=`echo $fs | cut -f2 -d:`
        MESSAGE="Subject: $HOSTNAME File System Alert: $FS at $SIZE %"
        echo $MESSAGE | mail $NOTIFY
done	

### Exit gracefully
exit 0

Put a set -x in the beginning after the shebang (#!/usr/bin/ksh) and look where there error occures, ie. post it here.

I can only see one test, so I'm guessing your df | awk combo are returning zilch.

Run that manually and check the result.

And change

if [ -z $FSLIST ]; then

to

if [ -z "$FSLIST" ]; then

ur means is

#! /usr/bin/ksh -x 

??

No. He meant

#!/usr/bin/ksh
 
set -x

but #!/usr/bin/ksh -x also seems to work!

Thanks alot.. after i edit to this.. no error...

---------- Post updated at 05:57 PM ---------- Previous update was at 05:56 PM ----------

Another question... if i wanna let it become everyday 8.00 am only send the df -k result..
how i need to modified

coz i now receive the email is in this format
Subject: hostname File System Alert: /u01 at 89 %

Hi.

You shouldn't need to modify the script. Just set up a cronjob to run it...

Something like...

0 8 1-5 * * /path/to/script > /dev/null 2>&1

and other question
coz now i receive the email is in this format,
Subject: mercury File System Alert: /u08 at 83 %

if i wanna change to this format
Filesystem kbytes used avail capacity Mounted on
/dev/vx/dsk/bootdg/rootvol
116961355 5997193 109794549 6% /
/proc 0 0 0 0% /proc
mnttab 0 0 0 0% /etc/mnttab
fd 0 0 0 0% /dev/fd
swap 38190616 16 38190600 1% /var/run
dmpfs 38190600 0 38190600 0% /dev/vx/dmp
dmpfs 38190600 0 38190600 0% /dev/vx/rdmp
swap 38190928 328 38190600 1% /tmp
/dev/vx/dsk/dssdg/vol01
150221824 78874641 66888002 55% /u01
/dev/vx/dsk/dssdg/vol02
141385728 65107028 71511298 48% /u02
mysolaris:/u10 516319545 72739146 438417204 15% /u10

any idea? =)

That looks like a full df?

cat << ! | mail $NOTIFY
Subject: $HOSTNAME File System Alert: $FS at $SIZE %"

$(df)
!

yap

i hope can do a full df..