Revised Script to Capture OVM information

I have created bash script month back to capture OVM information. Below is the link to that.

https://ervikrant06.wordpress.com/2014/06/02/script-to-capture-ovm-information/

Yesterday, in free time I thought of doing some modifications in it to organize data in well manner. After modifications I end up with below script which is used to capture information about the VM name, unique number associated with it, Guest OS type, Memory and vCPU.

#!/bin/bash

#Created By : vikrant Aggarwal

### To capture OVM VM information.

declare -a array1

declare -a array2

declare -a array3

declare -a array4

declare -a array5

for i in `df -Ph | awk ‘{print $6}’ | grep -i “^\/OVS”`

do

cd $i/VirtualMachines/

for j in `ls -lrt | awk ‘{print $9}’ | grep -v “^$”`

do

array1+=(`cat $j/vm.cfg 2>/dev/null | grep -w OVM_simple_name | awk ‘{print $3}’ | sed ‘s/.\(.*\)./\1/’`)

array2+=(`cat $j/vm.cfg 2>/dev/null | grep -w name | awk ‘{print $3}’ | sed ‘s/.\(.*\)./\1/’`) >/dev/null

array3+=(`cat $j/vm.cfg 2>/dev/null | grep -w guest_os_type | awk ‘{print $3}’ | sed ‘s/.\(.*\)./\1/’`) >/dev/null

array4+=(`cat $j/vm.cfg 2>/dev/null | grep -w memory | awk ‘{print $3}’`)

array5+=(`cat $j/vm.cfg 2>/dev/null | grep -w vcpus | awk ‘{print $3}’`)

done

done

printf “%-30s%-40s%-20s%-30s%s\n” “Server Name” “Name” “guest_os_type” “Memory” “VCPU”

for ((m=0;m<${#array1[@]};m++))

do

printf “%-30s%-40s%-20s%-30s%-5s\n” “${array1[m]}” “${array2[m]}” “${array3[m]}” “${array4[m]}” “${array5[m]}”

done

In near future I am planning to add getopts to give the options to select particular information as per requirement.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s