WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-users

[Xen-users] xenstat to bash arrays :)

To: Xen-users@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-users] xenstat to bash arrays :)
From: Tim Post <echo@xxxxxxxxxxxx>
Date: Sun, 16 Sep 2007 20:16:24 +0800
Delivery-date: Sun, 16 Sep 2007 05:17:10 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-users-request@lists.xensource.com?subject=help>
List-id: Xen user discussion <xen-users.lists.xensource.com>
List-post: <mailto:xen-users@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-users>, <mailto:xen-users-request@lists.xensource.com?subject=unsubscribe>
Organization: echoreply
Reply-to: echo@xxxxxxxxxxxx
Sender: xen-users-bounces@xxxxxxxxxxxxxxxxxxx
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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-users] xenstat to bash arrays :), Tim Post <=