Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to set a SHELL variable from Nawk/Awk/Gawk 1

Status
Not open for further replies.

madasafish

Technical User
Jul 18, 2006
78
TH
Given the output of "df -k"

I want to be able to read each LINE and assign a unique variable to each "space separated parameter"

If $5(%used) is > then 81(Fixed Variable) then I want to print the Variable $1 and the Variable $5 outside of awk/nawk/gawk.

Example
echo $1 is $5 full

Any help appreciated.

Madasafish2

Example output of df -k
df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda2 5842664 4566860 979004 83% /
/dev/hda1 101086 12354 83513 13% /boot
none 127808 0 127808 0% /dev/shm
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
There must be a more elegant way for AWK/NAWK/GAWK to export
SHELL variables rather then me calling gawk 3 times to set each SHELL variable

Any advice would be much appreciated

Madasafish

IFS='
'
for line in `df -k | gawk '$1 ~ /dev/ {print $0}'`
do
FILESYS=`echo $line | gawk '{print $1}'`
FSUSED=`echo $line | gawk '{print $5}' |gawk -F"%" '{print $1}'`
FSMNT=`echo $line | gawk '{print $6}'`

if [ "$FSUSED" -gt "80" ] && [ "$FSUSED" -lt "90" ]
then
RetVal=104 #Warning <---Set a Variable
GetMsg <---Call a SHELL function
ShowStatus <---Call a SHELL function
fi
done
 
sth. like this?

df -k |\
awk '$1 ~ /dev/ {print $1, substr($5,1,length($5)-1), $6}' |\
while read FILESYS FSUSED FSMNT
do
if [ ${FSUSED} -gt 80 -a ${FSUSED} -lt 90 ]
then
...
fi
done

HTH,

p5wizard
 
Thanks P5Wizard,

It worked a treat!

;-)

madasafish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top