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

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

Bugfix: var error

  • Property svn:executable set to *
File size: 2.2 KB
RevLine 
[196]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.$$"
[199]18drbl_vm_xentop_file="/tmp/drbl_vm_xentop.$$"
[196]19
20# [Main]
[200]21check_root
[196]22for client_IP in $client_IPs
23do
24    # local variables
25    IP_status="online"
26    client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $2}')"
[199]27    vm_numbers=""
[196]28    vm_hostnames=""
29    vm_IP=""
30    vm_CPU_core=""
31    vm_Ram=""
32    vm_CPU_loading=""
33    vm_Ram_loading=""
34    # check network status
35    ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline"
36   
37    if [ $IP_status == "online" ]; then
38        ssh -o StrictHostKeyChecking=no $client_IP "xentop -b -i1" >> $drbl_vm_xentop_file
39        vm_hostnames="$(cat $drbl_vm_xentop_file | sed -n '3,$p' | awk '{print $1}')"
40   
[199]41        printf "[$client_hostname] " >> $drbl_vm_file
42        printf "[$client_hostname] "
[196]43        declare -i i=1
44
[200]45        vm_numbers=$(echo $vm_hostnames | wc -w)
46
[199]47        printf "[Running VM: $vm_numbers]\n" >> $drbl_vm_file
48        printf "[Running VM: $vm_numbers]\n"
49
[196]50        for vm_hostname in $vm_hostnames
51        do 
52            vm_CPU_core="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $9}')"
53            vm_Ram="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $5}')"
54            vm_CPU_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $4}')"
55            vm_Ram_loading="$(cat $drbl_vm_xentop_file | grep $vm_hostname | awk '{print $6}')"
[200]56            printf "VM$i: $vm_hostname $vm_CPU_core ${vm_Ram}K $vm_CPU_loading%% $vm_Ram_loading%%\n" >> $drbl_vm_file
57            printf "VM$i: $vm_hostname VCPU=$vm_CPU_core Mem=${vm_Ram}K VCPU_loading=$vm_CPU_loading%% Mem_usage=$vm_Ram_loading%%\n"
[196]58            i=i+1
59        done
60   
[200]61    else
62        echo "[Error] $client_hostname $client_IP is offline !" && exit 2
63
[196]64    fi
[200]65
[196]66done
67
[199]68# dlete tmp file
69rm -f $drbl_vm_xentop_file
Note: See TracBrowser for help on using the repository browser.