[Solved] File System Monitoring Script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] File System Monitoring Script
# 1  
Old 10-14-2010
[Solved] File System Monitoring Script

Hello Scripts Guru

I had created a shell script to monitor the threshold of the file system, but some where it is not giving the correct output. Request to all to hel me out

I am getting the following output
Code:
/dev/vg00/lvol3 mounted on 1865224 10% / is 2097152%
/dev/vg00/lvol1 mounted on 1494288 18% /stand is 1835008%
/dev/vg00/lvol7 mounted on 2614408 75% /var is 10485760%
/dev/vg00/lvol8 mounted on 7469647 6% /var/adm/crash is 8454144%
/dev/vg00/lvol6 mounted on 2189632 58% /usr is 5242880%
/dev/vg00/lvol5 mounted on 2059336 1% /tmp is 2097152%
/dev/vg00/lvol4 mounted on 5109456 59% /opt is 12582912%
/dev/vg00/lv_app mounted on 121818 1% /app is 131072%
31457280 mounted on 72% /app/common is 22302271%

But I need a output, where if file system goes beyond 50% threshold, It should shows me output

Last edited by vbe; 10-14-2010 at 12:36 PM.. Reason: code tags please
# 2  
Old 10-14-2010
Your script:
Code:
#!/usr/bin/ksh
#
# SCRIPT: fs_mon_HP.ksh
# AUTHOR: Indrajit Bhagat
# DATE: 15-10-2010
# REV: 1.1.P
# PURPOSE: This script is used to monitor for full filesystems,
# which is defined as .exceeding. the FSMAX value.
# A message is displayed for all .full. filesystems.
#
# REV LIST:
#
# set -n # Uncomment to check syntax without any execution
# set -x # Uncomment to debug this script
#
##### DEFINE FILES AND VARIABLES HERE ####
FSMAX="50"              # Max. FS percentage value

WORKFILE="/tmp/df.work"                 # Holds filesystem data
>$WORKFILE                              # Initialize to empty
OUTFILE="/tmp/df.outfile"                # Output display file
>$OUTFILE # Initialize to empty
THISHOST=`hostname` # Hostname of this machine
######## START OF MAIN #############

bdf | tail +2 |awk '{print $1, $2, $4, $5, $6}' > $WORKFILE
# Loop through each line of the file and compare column 2

while read FSDEVICE FSVALUE FSMOUNT
do
  FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign typeset -i FSVALUE
  if [ $FSVALUE -gt $FSMAX ]
  then
       echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
       >> $OUTFILE
  fi
done < $WORKFILE # Feed the while loop from the bottom!!

if [[ -s $OUTFILE ]]
 then
    echo "\nFull Filesystem(s) on $THISHOST\n"
    cat $OUTFILE
    print
fi



---------- Post updated at 17:47 ---------- Previous update was at 17:37 ----------

Quote:
done < $WORKFILE # Feed the while loop from the bottom!!
Why?

---------- Post updated at 17:52 ---------- Previous update was at 17:47 ----------

Why not load only what you need:
Code:
bdf | tail +2 |awk '{print $1, $5, $6}' > $WORKFILE



---------- Post updated at 17:57 ---------- Previous update was at 17:52 ----------

after just correcting the bdf line as suggested I get for output:
Code:
Full Filesystem(s) on ant

/dev/vg00/lvol8 mounted on /var is 77%
/dev/vg00/lvol7 mounted on /usr is 88%
/dev/vg00/lvol10 mounted on /sm is 58%
/dev/vg00/lvol6 mounted on /opt is 88%
/dev/vg00/lvol12 mounted on /opt/java is 77%
/dev/vg00/lvol5 mounted on /home is 75%
/dev/esvg01/lvol7 mounted on /tsmx is 51%
/dev/esvg03/lvol13 mounted on /tsmx/storage is 75%
/dev/esvg01/lvol4 mounted on /data/www is 54%
/dev/esvg03/lvol11 mounted on /prd is 65%
/dev/r5vg04/lvol1 mounted on /prd/data/arch is 66%
/dev/esvg01/lvol1 mounted on /prd/data/mnt0 is 63%
/dev/esvg03/lvol5 mounted on /prd/data/mnt3 is 75%
/dev/esvg03/lvol4 mounted on /prd/data/mnt2 is 82%
/dev/esvg03/lvol3 mounted on /prd/data/mnt1 is 98%
/dev/esvg02/lvol3 mounted on /rdm is 53%
/dev/esvg02/lvol4 mounted on /rdm/data is 96%
/dev/esvg02/lvol5 mounted on /octant is 65%
/dev/esvg01/lvol3 mounted on /sm/export is 84%
/dev/esvg03/lvol10 mounted on /opt/sas/9.1.3 is 76%
/dev/esvg01/lvol5 mounted on /opt/patrol is 54%
/dev/esvg03/lvol6 mounted on /opt/oracle is 55%
/dev/esvg02/lvol1 mounted on /sas_wks is 76%



---------- Post updated at 17:58 ---------- Previous update was at 17:57 ----------

So what do you want then?

---------- Post updated at 18:00 ---------- Previous update was at 17:58 ----------

And now FMAX=80, and:
Code:
 echo "\n Filesystem(s) above $FSMAX% full on $THISHOST\n"

gives for ouput:
Code:
ant:/home/vbe $ bdf_sample.ksh   

 Filesystem(s) above 80% full on ant

/dev/vg00/lvol7 mounted on /usr is 88%
/dev/vg00/lvol6 mounted on /opt is 88%
/dev/esvg03/lvol4 mounted on /prd/data/mnt2 is 82%
/dev/esvg03/lvol3 mounted on /prd/data/mnt1 is 98%
/dev/esvg02/lvol4 mounted on /rdm/data is 96%
/dev/esvg01/lvol3 mounted on /sm/export is 84%



---------- Post updated at 18:01 ---------- Previous update was at 18:00 ----------

Just correct your bdf line, and all seems to work...

Last edited by vbe; 10-14-2010 at 01:37 PM..
This User Gave Thanks to vbe For This Post:
# 3  
Old 10-15-2010
Thanks for the quick help..I am able to get the output, but for not all file system

Bdf
Code:
wdkwe-root> bdf
Filesystem          kbytes    used   avail %used Mounted on
/dev/vg00/lvol3     819200  286136  528928   35% /
/dev/vg00/lvol1     298928   45856  223176   17% /stand
/dev/wdkwevg01/kwe_var
                   2097152    1614 1964573    0% /wdkwe/wms/var
/dev/wdkwevg01/kwe_opt
                   4194304 1744183 2320512   43% /wdkwe/wms/opt
/dev/wdkwevg01/kwe_opt_base
                   1536000  165186 1285191   11% /wdkwe/wms/opt/base
/dev/wdkwevg01/kwe_tmpi
                    524288    1229  490375    0% /wdkwe/tmpi
/dev/wdkwevg01/kwe_samba
                   1048576    1357  981774    0% /wdkwe/samba
/dev/wdkwevg01/kwe_log
                    524288    1229  490375    0% /wdkwe/log
/dev/wdkwevg01/kwe_links
                     65536    1118   60396    2% /wdkwe/links
/dev/wdkwevg01/kwe_home
                    262144    3652  244662    1% /wdkwe/home
/dev/vg00/lvol8    20480000 2992728 17350864   15% /var
/dev/vg00/lvol7    2097152 1521256  571416   73% /usr
/dev/vg00/lvol6     409600  125000  282440   31% /tmp
/dev/vg00/lvol5    3670016 3059912  605352   83% /opt
/dev/vg00/lvol4     212992  156056   56936   73% /home
/dev/wdkwevg01/proedi
                    786432  404331  360216   53% /home/proedi
/dev/vg00/app_common
                    327680  164373  153548   52% /app/common
/dev/vg00/informix  622592  296062  306174   49% /app/common/informix
/dev/wdkwevg01/kwe_log1
                   4194304  843840 3141092   21% /app/common/informix/logical/pkwe

I am using the below script:
Code:
#!/usr/bin/ksh
#
# SCRIPT: fs_mon_HP.ksh
# AUTHOR: Indrajit Bhagat
# DATE: 15-10-2010
# REV: 1.1.P
# PURPOSE: This script is used to monitor for full filesystems,
# which is defined as .exceeding. the FSMAX value.
# A message is displayed for all .full. filesystems.
#
# REV LIST:
#
# set -n # Uncomment to check syntax without any execution
# set -x # Uncomment to debug this script
#
##### DEFINE FILES AND VARIABLES HERE ####
FSMAX="50"              # Max. FS percentage value
export FSMAX
WORKFILE="/tmp/df.work"                 # Holds filesystem data
>$WORKFILE                              # Initialize to empty
OUTFILE="/tmp/df.outfile"                # Output display file
>$OUTFILE # Initialize to empty
THISHOST=`hostname` # Hostname of this machine
######## START OF MAIN #############

bdf | tail +2 |awk '{print $1, $5, $6}' > $WORKFILE
# Loop through each line of the file and compare column 2

while read FSDEVICE FSVALUE FSMOUNT
do
  FSVALUE=$(echo $FSVALUE | sed s/\%//g) # Remove the % sign typeset -i FSVALUE
  if [ $FSVALUE -gt $FSMAX ]
  then
       echo "$FSDEVICE mounted on $FSMOUNT is ${FSVALUE}%" \
       >> $OUTFILE
  fi
done < $WORKFILE # Feed the while loop from the bottom!!

if [[ -s $OUTFILE ]]
 then
    echo "\n Filesystem(s) above $FSMAX% full on $THISHOST\n"
    cat $OUTFILE
    print
fi

The output I am getting is:
Code:
wdkwe-root> sh testabcd
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/wms/var: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/wms/opt: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/wms/opt/base: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/tmpi: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/samba: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/log: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/links: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /wdkwe/home: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /home/proedi: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /app/common: Syntax error
testabcd[32]: test: Specify a parameter with this command.
testabcd[32]: /app/common/informix/logical/pkwe: Syntax error

 Filesystem(s) above 50% full on wdkwe

/dev/vg00/lvol7 mounted on /usr is 73%
/dev/vg00/lvol5 mounted on /opt is 83%
/dev/vg00/lvol4 mounted on /home is 73%


Please suggest how to resolve this error message..I am thinking for using printf to remove the above error. I want o/p of all file system which is exceding the threshold 50 %

Last edited by Scott; 10-15-2010 at 07:09 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Process dies when launched in system startup script

Good morning! I'm trying to add Maven to the system boot by the moment without success. Testing the operation of the script I realize that the process isn't persistent when the program is launched with the start option. ---- #Startup Script ---- #! /bin/sh # chkconfig: 345 99 1 #... (5 Replies)
Discussion started by: carpannav
5 Replies

2. HP-UX

[Solved] Increase the file system size

Dear Friends, I would like to increase the size of a file system from 10GB to 15GB. System is runing on HP-UX 11.31. Please help in the matter. Regards, Bhagawati Pandey (3 Replies)
Discussion started by: BPANDEY
3 Replies

3. HP-UX

[Solved] Mount HP-UX File System in Windows 7

Hello, We just got a rx4640 that is running on: HP-UX B.11.31 U ia64 2426088954 unlimited-user license There is a plenty of space in it and we would like to use it for storage. I can access with ftp and place the files in there but i need to mount the file system in every PC that is running... (7 Replies)
Discussion started by: gjk
7 Replies

4. 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

5. Shell Programming and Scripting

Help with File Monitoring Script

I am getting errors when I try to run the script I just made, any suggestiongs would be helpful. Please be gentle, Im still a newbie and learning on the go at an entry level position. #!/usr/bin/ksh # PURPOSE: This script is going to view the top 10 largest home directory Folders, then go in each... (11 Replies)
Discussion started by: gkelly1117
11 Replies

6. Shell Programming and Scripting

system monitoring script

Hi, Does anyone have an example system monitoring script to monitor drives, memory, etc. Need a good example. Cheers Walnutpony (4 Replies)
Discussion started by: walnutpony123
4 Replies

7. Shell Programming and Scripting

ZFS file system - memory monitoring

I am working on a server where the 'root' user ZFS filesystem. Now when I do Top commands it says only 750M free .But when I count the actual memory utilized it comes only to 12 GB and the total size of the server is 32G. I think rest of the space is held up by ZFS file system. Is there a... (5 Replies)
Discussion started by: prasperl
5 Replies

8. Shell Programming and Scripting

Shell Script for monitoring File system.

Hi, need help to write one shell script to monitor UNIX file systems and if any changes happend like deletion of any file, adding new file, time stamp changed, permisson changed etc. Script need to send alert mail to defined person/mail id. I request someone to help me to create the... (1 Reply)
Discussion started by: vjauhari
1 Replies

9. Shell Programming and Scripting

File monitoring script

Team, Attached 2 scripts for your validation(main script,mail script) Problem description: When its red it should wait for 10 seconds and then send a mail. If not red it should not send the mail i have done the below changes in the main script: if then if ... (4 Replies)
Discussion started by: whizkidash
4 Replies

10. Shell Programming and Scripting

file system monitoring script

Hi Does anyone know any website which contains examples of unix system monitoring scripts example? cheers (1 Reply)
Discussion started by: g-e-n-o
1 Replies
Login or Register to Ask a Question