System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Total Disk Space returning Negative number

SOLVED
Go to solution
viswanath emani
Occasional Visitor

Total Disk Space returning Negative number

The attched script when executed on HP-UX box returns the total disk space as negative value. Also there are a total of 35 HD's on that machine. I suspect that integer value is overflown which is resulting the negative number.

Could anyone please let me know if you have come accross this problem and had any solution.

5 REPLIES
R.K. #
Honored Contributor

Re: Total Disk Space returning Negative number

No Attachment..!
Don't fix that what ain't broke
Dennis Handly
Acclaimed Contributor

Re: Total Disk Space returning Negative number

What shell are you using? If you use ksh, it has 64 bit integer arithmetic.
Otherwise, you should track the space in terms of megabytes, not bytes.
Or you can use awk's double arithmetic.

See this recent thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1395380
R.K. #
Honored Contributor

Re: Total Disk Space returning Negative number

You can try this little script:


for I in `vxdisk list | grep -v DEVICE | awk '{print $1}'`
do
diskinfo /dev/rdsk/$I | grep size | awk '{print $2/1024/1024}' >> dsz
done
awk 'BEGIN {sum=0}{sum+=$1} END {print sum}' < dsz
rm dsz


NOTE: Size will come out in GB
Don't fix that what ain't broke
viswanath emani
Occasional Visitor

Re: Total Disk Space returning Negative number

sorry i missed the attachment. Here is the following script :

x=`/bin/id|/usr/bin/cut -c5-11`;
if [ $x != "0(root)" ];then exit $?;
else disksum=0;
for device in `/usr/sbin/ioscan -fknCdisk | /bin/grep -e /dev/rdsk/ | /bin/cut -d "/" -f4`;
do type=`/usr/sbin/diskinfo -v /dev/rdsk/$device |/bin/grep type |/bin/awk '{print $2}'`;
if [ "$type" = "CD-ROM" ]; then i=0; else i=`/usr/sbin/diskinfo -v /dev/rdsk/$device |/bin/grep size | /bin/awk '{ print $2 }'`; fi;
disksum=`/bin/expr $disksum + $i`;
done ;
disksum=`/bin/echo "$disksum / 1024" | /bin/bc`;echo "${disksum}";fi
Dennis Handly
Acclaimed Contributor
Solution

Re: Total Disk Space returning Negative number

>if [ $x != "0(root)" ]; then exit $?;
>else disksum=0;

I would suggest you not use else here. After exit, you don't need that case:
if [ $x != "0(root)" ]; then exit 1; fi
(( disksum=0 ))
...
if [ "$type" = "CD-ROM" ]; then (( i=0 ))
else
i=$(/usr/sbin/diskinfo -v /dev/rdsk/$device | awk '/size/ { print $2 }')
fi
(( disksum = disksum + i ))
done
(( disksum = disksum / 1024 ))

Or divide by 1024 in the loop so it won't overflow:
(( disksum = disksum + i / 1024 ))
done