Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

awk command not working in shell script

SOLVED
Go to Solution
Highlighted
Regular Advisor

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

1 ACCEPTED SOLUTIONS
Honored Contributor Honored Contributor

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
6 REPLIES
Honored Contributor Honored Contributor

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 Acclaimed Contributor

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

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 Honored Contributor

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 Esteemed Contributor

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

Re: awk command not working in shell script

Thanks for great responses. I used Spex's suggestion to resolve the issue.