source: drbl-virt/sbin/check_drbl_vm.sh @ 199

Last change on this file since 199 was 199, checked in by rock, 14 years ago

Add Function Code: Deploy vm to which host(drbl_PXE_PV-VM_deploy.sh)

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/bin/bash
2# Program:
3#   Check DRBL client status
4# Author:
5#   Jazz, Rock {jazz, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:                                                                                         
9#   2010/08/29  Rock    First release (1.0)
10
11source /opt/drbl-virt/conf/drbl-virt.conf
12source $Work_Path/functions_drbl_virt
13
14
15# [Varliables]
16client_IPs=$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $1}')
17drbl_vm_file="/tmp/drbl_vm_status.$$"
18drbl_vm_xentop_file="/tmp/drbl_vm_xentop.$$"
19
20# [Main]
21for client_IP in $client_IPs
22do
23    # local variables
24    IP_status="online"
25    client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $2}')"
26    vm_numbers=""
27    vm_hostnames=""
28    vm_IP=""
29    vm_CPU_core=""
30    vm_Ram=""
31    vm_CPU_loading=""
32    vm_Ram_loading=""
33    # check network status
34    ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline"
35   
36    if [ $IP_status == "online" ]; then
37        ssh -o StrictHostKeyChecking=no $client_IP "xentop -b -i1" >> $drbl_vm_xentop_file
38        vm_hostnames="$(cat $drbl_vm_xentop_file | sed -n '3,$p' | awk '{print $1}')"
39   
40        printf "[$client_hostname] " >> $drbl_vm_file
41        printf "[$client_hostname] "
42        declare -i i=1
43
44        vm_numbers=$(echo vm_hostnames | wc -w)
45       
46        printf "[Running VM: $vm_numbers]\n" >> $drbl_vm_file
47        printf "[Running VM: $vm_numbers]\n"
48
49        for vm_hostname in $vm_hostnames
50        do 
51            vm_CPU_core="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $9}')"
52            vm_Ram="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $5}')"
53            vm_CPU_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $4}')"
54            vm_Ram_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $6}')"
55            printf "VM$i: $vm_hostname $vm_CPU_core ${vm_Ram}M $vm_CPU_loading%% $vm_Ram_loading%%\n" >> $drbl_vm_file
56            printf "VM$i: $vm_hostname VCPU=$vm_CPU_core Mem=${vm_Ram}M VCPU_loading=$vm_CPU_loading%% Mem_usage=$vm_Ram_loading%%\n"
57            i=i+1
58        done
59   
60    fi
61done
62
63# dlete tmp file
64rm -f $drbl_vm_xentop_file
Note: See TracBrowser for help on using the repository browser.