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!

Script Help Needed 1

Status
Not open for further replies.

Birbone

MIS
Dec 20, 2000
141
US
Okay, I am stuck on this one and I know it has got to be something simple to fix. I am writing a script designed to calculate the total file size for each group on a box. Each group is called a F/E. The problem is, my results are giving negative numbers for some groups. This type of result does not show up when testing on smaller data files. Here's what the results look like:

bytes F/E
-972538505 042
1207406523 055
-2138419596 089
300164203 215
33815183 218
67786188 223

Here is my script. I am trying to work with adsolute values. If you can help, let me know.

BOX=”042 055 089 215 218 223”
FE=””

echo "bytes F/E" > WRKFILE
for FE in $BOX
do
ll /*/*/data$FE |grep -v ^total |awk '{print$5}' >TMPFILE
cat TMPFILE | while read RECORD
do
let FE_SIZE=${FE_SIZE}+$RECORD
done
echo "${FE_SIZE} $FE" >> $WRKFILE
done


I have tried this script with and without the {} around the variables, as well as replacing the "let" command line with
FE_SIZE=`expr $FE_SIZE + $RECORD`
Everything I have tested still gives the dashes when working with large data file directories.
-Bobby s-)
bwgunn@icqmail.com
 
Hi Birbone,

This is not the answer to your negative problem, and forgive me I am a beginner in scripting, but are you sure that the FE_SIZE is adding up correctly, because you don't initialise it, and thus it is not reinitialised next time you go through the loop

Queenie
 
Hi
you can add on awk like below.

df -c | grep mraid/toms | sort | awk '{s+=$4} {t+=$3} {u+=$2} {v=int(t/u*100)} END {print "\n Free Disk Space = " s " kBytes. \n Disk Space "v"% Used."}'


Sachin
 
Ok, I changed the script to read:

ll /*/acudir/data$FE|grep -v ^total| awk '{ total += $5 }END { print total," bytes"}

then tested it on a single FE group, the result showed:
1.82437e+07 bytes

the rusult I want is:
18243725 bytes

I will be dealing with FE directories who's total file sizes in bytes will be around 71427522000 bytes. How do I expand my variable size to allow for large numbers? I want to work with absolute values.
-Bobby s-)
bwgunn@icqmail.com
 
Hi Birbone
I am looking book here and I didn't see anything regarding long integer or flot So may be You can divided that total by 10000000000.

ll /*/acudir/data$FE|grep -v ^total| awk '{ total += $5 } {final=total/10000000} END { print final," bytes"}

Sachin


 
Hi Patel,
Here's the solution that finally worked for the long integer. Thanks for your help. I wouldn't have gotten this far without it. I am going to play with the {final=total/1073741824} functionality to also display the total file size in Gigs. Thanks.

for FE in $RANGE
do
ll /*/acudir/data$FE | grep -v ^total | awk '{FILE_SIZE += $5}END{printf("%11.0f bytes\n",FILE_SIZE)}'
done

Here's what the results look like:

41565492582 bytes
9391194662 bytes
-Bobby s-)
bwgunn@icqmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top