Monitoring Script - filesystem

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitoring Script - filesystem
# 1  
Old 07-22-2009
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

# Add filesystems you wish to skip from checking
FSLIST=`df -k | grep -v "cdrom" | grep -v "mnt"  | awk '{ \
                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

### Mail out the list if there is one
for fs in $FSLIST
        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

### Exit gracefully
exit 0

# 2  
Old 07-22-2009
Put a set -x in the beginning after the shebang (#!/usr/bin/ksh) and look where there error occures, ie. post it here.
# 3  
Old 07-22-2009
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

if [ -z "$FSLIST" ]; then

# 4  
Old 07-22-2009
ur means is
#! /usr/bin/ksh -x


Last edited by Yogesh Sawant; 07-22-2009 at 05:35 AM.. Reason: added code tags
# 5  
Old 07-22-2009
No. He meant

set -x

but #!/usr/bin/ksh -x also seems to work!
# 6  
Old 07-22-2009
Originally Posted by scottn
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

if [ -z "$FSLIST" ]; then

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 %
# 7  
Old 07-22-2009

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script for Monitoring Root Filesystem

I am on SCO UNIX, I need to write a script to monitor root file system. For some reason it's not working for me. #!/bin/sh df -B / | awk '{ print $5 " " $1 }' | while read output; do echo $output if ; then echo "Running out of space \ HOSTNAME" # mail -s "Alert: Almost out of... (8 Replies)
Discussion started by: samnyc
8 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Filesystem getting full. Need a monitoring script

Hi, I am new to shell scripting in unix HP-UX. I need to determine how much a perticular file system is full and if it goes over 80% it should notify through mail about which are the files which are greater than 1 GB size. I used df -k command it is showing the alloocated KB and the %used... (14 Replies)
Discussion started by: Soma Das
14 Replies

3. UNIX for Advanced & Expert Users

ldapsearch in monitoring script without bind password written in script

Hi I do a very simple monitoring of our OpenLDAP (runs in cronjob and generate alerts if unsuccessfull) $ ldapsearch -h hostname.domain -D "cn=monitor_user,ou=People,dc=organisation" -w "password" -b "dc=organisation" -x "(&(cn=monitor_user)(ou=People))" dn | grep -v version dn:... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

4. AIX

Mount Filesystem in AIX Unable to read /etc/filesystem

Dear all, We are facing prolem when we are going to mount AIX filesystem, the system returned the following error 0506-307The AFopen call failed : A file or directory in the path name does not exist. But when we ls filesystems in the /etc/ directory it show -rw-r--r-- 0 root ... (2 Replies)
Discussion started by: m_raheelahmed
2 Replies

5. UNIX for Dummies Questions & Answers

hwo to find shared filesystem and local filesystem in AIX

Hi, I wanted to find out that in my database server which filesystems are shared storage and which filesystems are local. Like when I use df -k, it shows "filesystem" and "mounted on" but I want to know which one is shared and which one is local. Please tell me the commands which I can run... (2 Replies)
Discussion started by: kamranjalal
2 Replies

6. AIX

Performance Monitoring of FileSystem

As I am new to the Unix field, I would like to get the clarification regarding the Filesystem. The scenario is.. The filesystem (/drbackup) is getting monitored and if it exceeds the threshold, we will receive an alert from it. The issue is that we receive an alert with the description of... (2 Replies)
Discussion started by: A.Srenivasan
2 Replies

7. Shell Programming and Scripting

Monitoring script

Hi, I want to write script that monitors particular ports in a server. I completed the script but.... If the server is restarted i need manually start the script.. Is there any way i can make the script start by it self after the server reboot........ Thanks, Firestar (4 Replies)
Discussion started by: firestar
4 Replies

8. Shell Programming and Scripting

Help with Monitoring script

Hi Gurus, Currently I am learning UNIX through online forums and unix blogs. I have the below requirement. I need to write a script to monitor server processes. For example, there are 3 processes currently running on the server.(java, pmrepagent, pmserver). If any of the process goes down,... (2 Replies)
Discussion started by: svajhala
2 Replies

9. AIX

Help with a filesystem monitoring script.

I'd like to create a cron script that checks filesystems. For example if it reaches 95% USED, I'd like it to send me an email. Can this be possible for up to say 4 filesystems using the df -k command? Any samples to get me started would be much appreciated. (7 Replies)
Discussion started by: NycUnxer
7 Replies

10. Shell Programming and Scripting

Filesystem Monitoring script problems

Hi there all, #!/usr/bin/ksh Set -x MIN_MB_FREE="100MB" # Min. MB of Free FS Space MAX_PERCENT="85%" # Max. FS percentage value FSTRIGGER="1000MB" # Trigger to switch from % Used to MB Free WORKFILE="/tmp/" # Holds filesystem data >$WORKFILE #... (0 Replies)
Discussion started by: draco
0 Replies
Login or Register to Ask a Question