source: branches/stable/tools/action2qemu @ 1288

Last change on this file since 1288 was 1288, checked in by bruno, 12 years ago

Script to launch actions on all VMs as root

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/bin/bash
2#
3# $Id$
4#
5# Script to act on various distributions with qemu
6#
7
8# Syntax: action2qemu script [[vm1][..|vmx]]
9
10(
11dname=`dirname $0`
12prem=`echo $dname |cut -c1`
13if [ _${prem} = _"/" ]; then
14    export TOOLHOME=$dname
15else
16    export TOOLHOME=${PWD}/$dname
17fi
18
19. $TOOLHOME/common-env
20. $TOOLHOME/distro-env
21
22if [ _"$1" != _"" ]; then
23    export SCRIPT=$1
24    shift
25else
26    echo "Syntax: action2qemu script [[vm1][..|vmx]]"
27    exit -1
28fi
29
30if [ _"$1" = _"" ]; then
31    export VMS=`cat ${TOOLHOME}/DISTROS` 
32else
33    export VMS="$*"
34    single=1
35fi
36
37chmod 755 $SCRIPT
38
39for m in $VMS; do
40    echo "Working on $m"
41    vmp=0
42    if [ ! -f /users/qemu/$m.qemu ]; then
43            echo "VM unaccessible. Verify NFS mount"
44            exit -1
45    fi
46    if [ _"$sp" = _"" ]; then
47        export sp=2222
48    fi
49    ps auxww | grep qemu | grep -v grep | grep -q /users/qemu/$m.qemu
50    if [ $? -ne 0 ]; then
51        # Virtual machine alreday started
52        vmp=1
53        $TOOLHOME/mkqemu $m &
54        sleep 300
55    fi
56    scp -P $sp -p $SCRIPT root@localhost:/tmp
57    bn=`basename "$SCRIPT"`
58    ssh -q -p $sp root@localhost "/tmp/$bn"
59    if [ $vmp -eq 1 ]; then
60        ssh -q -p $sp root@localhost "halt -p"
61        sleep 300
62        proces=`ps auxww | grep qemu | grep -v grep | grep /users/qemu/$m.qemu | awk '{print $2}'`
63        if [ "$proces" != "" ]; then
64            kill $proces
65            sleep 10
66        fi
67    fi
68done
69
70) 2>&1 | tee /tmp/action2qemu.log
Note: See TracBrowser for help on using the repository browser.