myjess
December 21, 2008, 4:46am
1
Hi;
If I do something like this.
dftotalsize=0;export dftotalsize;df -k | grep \/db001 | awk '{print $4}' | while read theinput \
; do export $theinput; dftotalsize=`expr $dftotalsize + $theinput`; export dftotalsize; echo $dftotalsize; done ; echo `expr $dftotalsize \/ 1024 \/ 1024 "GB"
Is there a shorter way to do this because this will not fit on the one line.
Thanks.
df -k | awk '{sum+=$4}' END {print sum / 1024 /1024, "GB"}'
Lakris
December 21, 2008, 5:25am
3
Hi,
well You don't have to have it on one line, do You? Whereever there is a ; just use ENTER instead to go to a new line.
And I don't think You need to export the variables. Instead of
dftotalsize=`expr $dftotalsize + $theinput`
You could use
dftotalsize=$((dftotalsize+theinput))
/Lakris
myjess
December 21, 2008, 7:12am
4
Absolutely awesome. Shoot, I thought i knew a bit about scripting and awk, and I was right, I know a BIT about it, but that is beautiful.
Thanks so much for that.
myjess
December 21, 2008, 7:13am
5
lakris:
Hi,
well You don't have to have it on one line, do You? Whereever there is a ; just use ENTER instead to go to a new line.
And I don't think You need to export the variables. Instead of
dftotalsize=`expr $dftotalsize + $theinput`
You could use
dftotalsize=$((dftotalsize+theinput))
/Lakris
Thanks, but I think I wil go for the other option using awk. It also seems to give floating point numbers, whereas my way only gave the integers.