DevSupport
asked on
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:
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
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"
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
ASKER
@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 .
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 .
Remove the first, use sed to add a + between entries and then evaluate ....
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.
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
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.
Oh, do your systems have SNMP enabled so that data can be pulled using snmpget/snmpwalk?
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
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.
ASKER
@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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You!!
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,media
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,device