[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-users] xenstat to bash arrays :)



Hello all, 

I have modified some of my programs that use libxenstat to produce bash
arrays of running VM's, below is a sample of the output:

root@tower:/root# xm-shdomains
# Xen guest info
# Generated by xm-shdomains

guest_name[0]="Domain-0"
guest_id[0]=0
guest_cpu[0]=40
guest_mem[0]=85
guest_vcpus[0]=2

guest_name[1]="edgy1"
guest_id[1]=6
guest_cpu[1]=0
guest_mem[1]=13
guest_vcpus[1]=1

total_guests=1
# End Xen guest info.

With that output, you can use simple bash scripts to validate a dom-u 
as running, dead, whatever, i.e. :

root@tower:/root# ./chkdom edgy1
Domain edgy1 is running.
root@tower:/root# echo $?
0
root@tower:/root# ./chkdom edgy2
Domain edgy2 is not running.
root@tower:/root# echo $?
1
root@tower:/root#

The code (bash) is very simple:

root@tower:/root# cat chkdom
#!/bin/bash

xm-shdomains > /tmp/$$.domains
source /tmp/$$.domains
rm -f /tmp/$$.domains

target="$1"

i=0

while [ $i -le $total_guests ]; do
        if [ ${guest_name[i]} = "$target" ]; then
                echo "Domain $target is running."
                exit 0
        fi
        let "i += 1"
done

echo "Domain $target is not running."
exit 1
root@tower:/root#

If anyone wants a copy, e-mail me. I need to clean up the XML stuff that
is in other programs in the repo before release.

This is super handy for init scripts and other stuff :)

Soon coming, PHP arrays :)

Best,
--Tim



_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.