[HPADM] SUMMARY Scripting question

From: Thomas Northup (thomaslnorthup@yahoo.com)
Date: Fri Apr 02 2004 - 13:19:07 EST


A big thanks to John Adams, Kevin O'Donovan, Bertrand Hutin, Neeraj Lal, Roy Kidder, David Lee Totsch, Jeffrey Thomas.
 
I ending up using sort of a combination of some of the answers and used this...
STATUS=`/usr/bin/grep "file usage" /file/iwant/toLOOKat | /usr/bin/tail -n 1 | tail -c -7 | cut -c 1-3`
if [ "$STATUS" -ge 75 ]
then
    <action to be performed>
fi
-----------------------------------------------------------
JEFFREY THOMAS,
I’m not sure what shell you are using, but here’s on for the ksh:
# x=`grep 'file usage' filename | tail -1 | awk '{print $7}' | cut -f1 -d.` # if [[ $x -gt 75 ]]
# then
action..
# fi
-----------------------------------------------------------
David Lee Totsch
Thomas:
awk -F'[ %]' '$7 > 75 {print $0}'
the '[ %]' tells awk to use both spaces and percent-signs as field separators...
-dlt-
-----------------------------------------------------------
Roy Kidder
This should do what you want:
#!/bin/sh
while read line
do
  PCT="`echo $line | cut -f7 -d' ' | cut -f1 -d'.'`"
  if [ $PCT -gt 75 ]
  then
    echo $PCT
  fi
done < input.txt
Hope that helps,
Roy
-----------------------------------------------------------
Neeraj Lal
Hi Thomas
Here is the script
awk <test.txt \
'
{
a=substr($0,50,5) ;
if (a >= "075.0")
{
printf "WARNING\n"
}
else
{
printf "OK\n"
}
}
'
test.txt is your input file you can change the position of substr as per yor input file
-----------------------------------------------------------
Bertrand Hutin
awk '{sub("%","");if ($7 > 75) printf "command to execute %s\n",$0}'
file
for instance:
command to execute file usage ................ __112035 __1750.5 MB
085.5
command to execute file usage ................ __131072 __2048.0 MB
100.0
-----------------------------------------------------------
Kevin O'Donovan
Hi,
I guess you mean at the end of each line?
Use read to take it a line at a time, piping through tail -c -6 to get the last 6 characters, pipe through cut -c 1-5 to get rid of the %.
Then do an if [[ $number -gt $threshold ]]; then .... Fi
while (read line)
do
  number=`echo $line | tail -c -6 | cut -c 1-5`
  if [[ $number -gt 75 ]]; then
    <do the action>
  fi
done
 I think that should do it, haven't tried it but could well work.
 Kevin.
--------------------------------------------------------------

John Adams

RECORD=null
 
while [ ! "$RECORD" = "" ]
do
   PERCENT=`echo $RECORD |awk '{print $NF}'`
   NUMERIC_PERCENT=`echo $PERCENT|cut -f1 -d'%'`
   if [ $NUMERIC_PERCENT -gt 75 ]
   then
        echo "Insert action here"
   fi
   read RECORD
done <your_filename_here
 
This isn't exactly pretty, but it will work. It has the second upside of being able to, with a simple modification, have a tail -f redirected into it so it'll act in background as a cheap knock-off daemon.
 
Good luck!
 
J
 

Thomas Northup <thomaslnorthup@yahoo.com> wrote:

Hello admins,

I have a file that looks like the one below. I need a script that will examine the percentage at the end and perform some action if the percentage is over 75%.

 

file usage ................ ___22949 ___358.6 MB 017.5%

file usage ................ ___47817 ___747.1 MB 036.5%

file usage ................ ___51356 ___802.4 MB 039.2%

file usage ................ ___53498 ___835.9 MB 040.8%

file usage ................ ___54431 ___850.5 MB 041.5%

file usage ................ ___64050 __1000.8 MB 048.9%

file usage ................ ___16218 ___253.4 MB 012.4%

file usage ................ ___37355 ___583.7 MB 028.5%

file usage ................ ___75336 __1177.1 MB 057.5%

file usage ................ ___96696 __1510.9 MB 073.8%

file usage ................ __112035 __1750.5 MB 085.5%

file usage ................ __131072 __2048.0 MB 100.0%

 

 

 

TIA (will summarize)

Thomas

---------------------------------
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway - Enter today

---------------------------------
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway - Enter today

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:40 EDT