finding total size of disks using wmic

Hi Experts,

I am trying to get total disk size from multiple servers and wmic is what I am trying to use.

However I am unable to add the results coming from wmic to find the total disk space. I am trying something like this:

sizelist=`winexe -U rpega/$u%$p //$i "WMIC LOGICALDISK where drivetype=3 get size"|sed s/^M//g`
echo $sizelist > sizelist.file
sizearr=($sizelist)

counter=1
result=0
re='^[0-9]+$'
        while [ "${sizearr[$counter]}" != "" ]; do
          if ! [[ ${sizearr[$counter]} =~ $re ]]; then
        result=`expr $result + ${sizearr[$counter]}`
        fi
        counter=$(expr $counter + 1)
        done

echo "the total size is $result"

Open in new window


i am very bad at shell scripting so the above code may look weird. Please feel free to change it, i would like to be able to add the results coming from wmic command to get total disk allocation size.

The wmic command gives results like this:

Size
107005075456
966230274048
214612045824
53550772224
1429227958272

and I would like to be able to add these numbers and get the result.

Thanks
DevSupportAsked:
Who is Participating?
 
arnoldCommented:
The point is to add + on each line first
Then the echo $((sizelistresults)) will sum the data...
One could pipe that to bc...

Try the following

sizelistresult=`winexe -U rpega/$u%$p //$i "WMIC LOGICALDISK where drivetype=3 get size"|grep -vi 'size' | sed -e 's/^M//g' `

echo $(( `echo $sizelistresults | sed -e 's/$/\+/' |sed -e 's/\s*//g' | sed -e 's/\+$//' ` ))

See what you get mainly first see whether the inside outs the numbers as
Number+
Number+
Number

...
1
 
arnoldCommented:
you might want to use powershell

On what basis are you looking to combine. the logical volumes might be parts of several different subsystems

I.e. you have three disks with the first one partition, disk 2 two partitions, disk 3 three partitions.
How do you want the logical volumes to be combined for a total ?


potentially you are interested in
wmic diskdrive get name,partitions,size,mediatype

This gives you info on drives and their full capacity and number of partition on each physical drive....

in combination with
wmic partition get diskindex,name,size,deviceid
0
 
DevSupportAuthor Commented:
@arnold:
I have a requirement wherein I need to add up the disk drives (total size) of logical disks and enter it into an inventory database.

We have like 200 systems from which I am collecting total size of all drives..so that we can estimate how much storage is allocated to these systems.

I need only WMIC LOGICALDISK where drivetype=3 get size

and then total it 107005075456 + 966230274048 + 214612045824

As I am collecting this data using a unix system I use command prompt as its easier as opposed to powershell as winexe doesn't like powershell and tends to get stuck

I know its a mess but we have been using this system for all other data capturing requirements from windows and unix systems and it works .
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
arnoldCommented:
Remove the first, use sed to add a  + between entries and then evaluate ....
sizelist=$((winexe -U rpega/$u%$p //$i "WMIC LOGICALDISK where drivetype=3 get size"| grep -I v "Size"|sed s/^M/\+/g))
echo $sizelist > sizelist

Open in new window


See what the output is.
Alternatively
Use your example with my modification replacing the empty line feed \r) with a plus then echo $((sizelist)) which shoukd return the sum of the results in bytes.
0
 
arnoldCommented:
Oh, do your systems have SNMP enabled so that data can be pulled using snmpget/snmpwalk?
0
 
arnoldCommented:
sizelist=$((`winexe -U rpega/$u%$p //$i "WMIC LOGICALDISK where drivetype=3 get size"|grep -vi 'size' | sed -e 's/^M/\+/g'  |sed -e 's/\+$//' -e 's/\s*//g' ` ))
echo "total Storage for drives is : $sizelist

Open in new window


the first converts the list
Size
107005075456
966230274048
214612045824
53550772224
1429227958272
into
107005075456+
966230274048+
214612045824+
53550772224+
1429227958272
then prior to assigning the $(( )) block has the shell re-evaluate the results.
or after the assignment ....
on the variable.
0
 
DevSupportAuthor Commented:
@arnold:
Thank you for your response, I did
sizelistresult=`winexe -U rpega/$u%$p //$i "WMIC LOGICALDISK where drivetype=3 get size"|grep -vi 'size' | sed -e 's/^M/\+/g'  |sed -e 's/\+$//' -e 's/\s*//g' `

echo "$sizelistresult" > sizel.fil

and sizel.fil conatins

107005075456
1019918397440
182400823296
53550772224
1810193428480

looks like the + is not appearing or being evaluated.

Wondering if you could help.

Thank you!
0
 
DevSupportAuthor Commented:
Thank You!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.