Operating System - Linux
1745829 Members
4046 Online
108722 Solutions
New Discussion юеВ

awk command not working in shell script

 
SOLVED
Go to solution
vz7r1x
Regular Advisor

awk command not working in shell script

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

6 REPLIES 6
Peter Godron
Honored Contributor

Re: awk command not working in shell script

Hi,
and welcome to the forums !

You may be interested in reading:
https://community.hpe.com/t5/forums/searchpage/tab/message?q=awk+command+
Please also read:
https://community.hpe.com/t5/Community-FAQ/FAQ-Kudos/td-p/6838486 on how to reward any useful answers given to your questions.

James R. Ferguson
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...

spex
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
Sandman!
Honored Contributor
Solution

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
Arturo Galbiati
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
vz7r1x
Regular Advisor

Re: awk command not working in shell script

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