The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: would like to see how others would do this...
Hopper
Newbie
Rank: 1



UID 176
Digest Posts 0
Credits 0
Posts 58
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
would like to see how others would do this...



would like to see how others would do this...



i get an output from a script like:

rlink: rlk_ecims-dr_lloravol_rvg
state: active
status: has 1833 outstanding writes, occupying 66328 kbytes (0%) on the srlis behind by 00:00:08 hours

flags: write enabled attached consistent connected asynchronous
protocol: udp/ip


if i wanted to keep an eye on either the percentage or the time, how would you parse this output? more specifically, this is the output of veritas replicator. i would like an email if either a) the percentage is higher than 50% or b) more than 3 hours behind.
i would love to see how someone else would do this with a .sh script...
thanks,


Top
d16man
Newbie
Rank: 1



UID 104
Digest Posts 0
Credits 0
Posts 52
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
here's an awk implementation. modify to suit your needs

code:

awk 'begin { threshold=50;
             timetheshold=3;
             sysadmin="root";
             email="/usr/bin/mailx "
     }
     /status/{
               for(i=1;i<=nf;i++) {
                  if ( $i ~ /^\(/ ) { gsub(/[(%)]/,"",$i)
                       percent=$i
                  }
                  if ( $i ~ /behind/) { time=$(i+2) }
               }
     }
     end{
           n=split(time,timearr,":")          
           if ( percent > threshold ||  int(timearr[1]) > timethreshold) {
               cmd = email sysadmin   
               print "body text " | cmd  
               close(cmd)
               print "email sent"
           }
Top
clvezlys
Newbie
Rank: 1



UID 92
Digest Posts 0
Credits 0
Posts 44
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
wow, that was fast! i'll give this a whiz today and let you know. thanks ghostdog74!
Top
astrovineet
Newbie
Rank: 1



UID 61
Digest Posts 0
Credits 0
Posts 27
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
praveen,
coincidently, my solution is very similar to yours.
the issue that i see in your solution is the fact that you are loading
the entire file into one string.
this can cause problems in the performance for large files.
here is my solution not loading the entire file into a string:

code:

typeset -i mpctlimit=50
typeset -i mtimelimit=3

minpfile='b'
mtimere='[0-9][0-9]:[0-9][0-9]:[0-9][0-9]'
mhhre='[0-9][0-9]'
mmmssre='[0-9][0-9]:[0-9][0-9]'

mperctline=`sed -n '/.*%.*/p' ${minpfile}`
mperctvalue=`echo ${mperctline} | sed 's/.*(\([0-9].*\)%).*/\1/'`
echo "mperct = "$mperctvalue" limit = "${mpctlimit}
if [ ${mperctvalue} -gt ${mpctlimit} ];then
echo "above the percentage limit"
fi

mhoursline=`sed -n "/.*${mtimere}.*/p" ${minpfile}`
mhoursvalue=`echo ${mhoursline} | sed "s/.*\(${mhhre}\){mmmssre}.*/\1/"`
echo "mhours = "$mhoursvalue" limit = "${mtimelimit}
if [ ${mhoursvalue} -gt ${mtimelimit} ];then
Top
DMK
Newbie
Rank: 1



UID 118
Digest Posts 0
Credits 0
Posts 41
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
a variation from praveenkumar_l's solution where precentage and hours are read from file with one sed command.

code:
usage=50
time_limit=3

sed  -n 's/.*\([0-9]\+\)%.*\([0-9][0-9]\):[0-9][0-9]:[0-9][0-9].*/\1 \2/;t;p' out.txt | \
echo "${percentage}% ${hours}h"

if [[ $percentage -gt $usage ]] ;then
   echo "disk usage beyond $usage%"
   #send mail
fi

if [[ $hours -gt $time_limit ]] ;then
   echo "time limit beyond $time_limit hours"
   #send mail
fi
Top
Bestmiler
Newbie
Rank: 1



UID 69
Digest Posts 0
Credits 0
Posts 15
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
thank you all for the quick responses. i'm going to be working on this later this afternoon and i'll see what i end up with, if wanted i'll share my code when finished.
Top
Grayscale
Newbie
Rank: 1



UID 164
Digest Posts 0
Credits 0
Posts 8
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:39 AM  Profile | P.M. 
execute your script with -x option and post the trace please.
Top
 

 

All times are GMT, the time now is Mar 11, 2010 08:22 PM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.008405 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP