awk command not working in shell script (6943 Views)
Reply
Regular Advisor
vz7r1x
Posts: 183
Registered: ‎12-05-2006
Message 1 of 7 (6,943 Views)
Accepted Solution

awk command not working in shell script

[ Edited ]

I am trying to grab output from awk utility in a script and email the output but script is failing. On HP 11 platform, I trying to get the fifth field from "bdf /var" output and send myself an email if /var is 90% or more full but I have not been able to get it right.

Output is needed for second line as first line has the header, not disk info. Here is what I wrote:

#!/bin/sh
bdf /var |sed 's/%//'|awk '{if ($5 >= 90) print $0;}'|mailx -s"`hostname` -File system full" MyId@email.com
exit

And bdf output is like this:
Server> bdf
Filesystem kbytes used avail %used Mounted on
/dev/vg00/lvol7 4194304 1756256 2422400 42% /var

 

 

 

P.S.This thread has been moved from HP-UX>General HP-UX > languages-HP Forums Moderator

Honored Contributor
Peter Godron
Posts: 4,470
Registered: ‎02-13-2002
Message 2 of 7 (6,943 Views)

Re: awk command not working in shell script

Hi,
and welcome to the forums !

You may be interested in reading:
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=110170

Please also read:
http://forums1.itrc.hp.com/service/forums/helptips.do?#33 on how to reward any useful answers given to your questions.

Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 3 of 7 (6,943 Views)

Re: awk command not working in shell script

Hi:

To skip the header line you could do:

# bdf /var |sed 's/%//'|awk '{if (NR>1 && $5 >= 90) print $0;}'

Regards!

...JRF...

Honored Contributor
spex
Posts: 1,367
Registered: ‎05-14-1996
Message 4 of 7 (6,943 Views)

Re: awk command not working in shell script

Islam,

Here's an adaptation of a script I use to check/copy Oracle archivelogs:

#!/usr/bin/sh
typeset -i SIZE=$(bdf /var| awk '{getline; sub(/%/,""); print $5;}')
if [[ $SIZE -gt 90 ]]
then
mailx -m -s "[$(date +%m\/%d\/%y)] $(hostname) /var at 90+%!" your@email.addr
fi
exit 0

PCS
Honored Contributor
Sandman!
Posts: 2,220
Registered: ‎01-13-2005
Message 5 of 7 (6,943 Views)

Re: awk command not working in shell script

how about the awk below:

# bdf /var | awk 'z[split($5,z,"%")-1]>=90' | mailx -s "FileSys > 90%" abc@xyz.com
Esteemed Contributor
Arturo Galbiati
Posts: 830
Registered: ‎02-10-2003
Message 6 of 7 (6,943 Views)

Re: awk command not working in shell script

HI,
# Show mount points over PCT
bdf|awk -v PCT=90 'NR==1||substr($5,1,index($5,"%")-1)+0>=PCT'

if you do not want header remove "NR==1||".
if you want different percentage to check chnage PCT=90 as you prefer.
HTH,
Art
Regular Advisor
vz7r1x
Posts: 183
Registered: ‎12-05-2006
Message 7 of 7 (6,943 Views)

Re: awk command not working in shell script

Thanks for great responses. I used Spex's suggestion to resolve the issue.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.