Hello Gurus,
I am firing the below command :
df -g | grep -v var| awk '{ (if $4 > 90% ) print "Filesystem", $NF,"over sized";}'
But I am getting the below error:-
syntax error The source line is 1.
The error context is
{if ($4 > >>> 90%) <<<
awk: The statement cannot be correctly parsed.
The source line is 1.
Please suggest.
Thanks-
Pokhraj
df -g | grep -v var| awk '{ if ( $4 > "90%" ) print "Filesystem", $NF,"over sized";}'
Hello,
Could you please try theis following code and let me know if this helps.
$ df -g | grep -v "var" | awk '{sub(/\%/,"",$0)} {print$1" "$4}' | awk '{ if ( $2> "90" ) print $1 ,"over sized";}'
Filesystem over sized
/mnt over sized
Thanks,
R. Singh
Thanks Anbu23 for your help.
But the command throwing some extra lines as below:-
Filesystem on over sized
Filesystem /febsmt/orasoft_bck over sized
Filesystem /febsdb/orasoft over sized
Why this line is coming.. Any idea.
Thank-
Pokhraj
df -g | grep -v var| awk ' NR>1 { if ( $4 > "90%" ) print "Filesystem", $NF,"over sized";}'
rveri
July 3, 2013, 3:07am
6
pkhraj_d,
check this out..
df -g | grep -v -e var -e Filesystem | sed 's/%/ /g'|awk '{ if ( $4 > 90 ) print "FILESYSTEM", $NF,"over sized";}'
Enjoy.
pamu
July 3, 2013, 3:12am
7
df -g | grep -v var| awk '$4+0 > 90{print "Filesystem", $NF,"over sized"}'
RudiC
July 3, 2013, 3:19am
8
No need for grep
nor more than one pipe:
df -g| awk 'NR==1 || /var/ {next} {sub (/%/,"",$4); if ($4+0 > 90) print "Filesystem ", $NF, "oversized"}'
And, yes, pamu is right: no need for the sub
and the if
:
df -g | awk 'NR==1 || /var/ {next} $4+0 > 90 {print "Filesystem ", $NF, "oversized"}'
1 Like
rveri
July 3, 2013, 4:01am
9
RudiC ,
great code,
df -g | awk 'NR==1 || /var/ {next} $4+0 > 90 {print "Filesystem ", $NF, "oversized"}'
$4+0 what it means, if you could explain. How it is eliminating the "%"symboll which is in there.
Thank you,
RudiC
July 3, 2013, 4:20am
10
awk
, when converting a field to a number, interprets leading digits in a field as a number and stops at the first non-digit. Adding zero to a field forces number conversion, so here you go: awk
takes the digits and stops at the %- sign: 90%+0
is becoming 90 and can be compared numerically.
1 Like