[HPADM] SUMMARY Scripting question
From: Thomas Northup (thomaslnorthup_at_yahoo.com)
Date: 04/02/04
- Previous message: Thomas Northup: "[HPADM] SUMMARY Scripting question"
- In reply to: Thomas Northup: "[HPADM] Scripting question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 2 Apr 2004 10:19:17 -0800 (PST) To: hpux-admin@DutchWorks.nl
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)
- Previous message: Thomas Northup: "[HPADM] SUMMARY Scripting question"
- In reply to: Thomas Northup: "[HPADM] Scripting question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
- [HPADM] SUMMARY Scripting question
... A big thanks to John Adams, Kevin O'Donovan, Bertrand Hutin, Neeraj Lal, Roy Kidder,
David Lee Totsch, Jeffrey Thomas. ... test.txt is your input file you can change
the position of substr as per yor input file ... Do you Yahoo!? ... (HP-UX-Admin) - Re: Wahooo!!!
... Nice, KEVIN. ... I'm sure Earthink and you differ on the definition of stalking,
KEVIN since that was the first time I emailed you. ... > Do You Yahoo!? ... Mail
has the best spam protection around http://mail.yahoo.com. ... (rec.boats) - Re: Problem sending email from Windows XP / Apache 2 /php 5.0
... Kevin wrote: ... > Maybe Yahoo requires authentication for SMTP?
... > class, which supposedly supports authentication. ... (comp.lang.php) - Re: PySQLLite Speed
... Kevin wrote: ... > I wanted to thank Roger Binn for his email. ...
batches of whatever size you choose and write the individual batches to the db. ... >
Do you Yahoo!? ... (comp.lang.python)