source: drbl-virt/sbin/check_drbl_client.sh @ 204

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

Bugfix: correct path & delete unused sh

  • Property svn:executable set to *
File size: 2.0 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_client_file="/tmp/drbl_client_status.$$"
18drbl_client_top_file="/tmp/drbl_client_top.$$"
19
20
21# [Main]
22drbl_sshkey
23for client_IP in $client_IPs
24do
25    # local variables
26    client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | grep $client_IP | awk '{print $2}')"
27    IP_status="online"
28    client_CPU_core=""
29    client_Ram=""
30    client_idle_CPU=""
31    client_unused_Ram=""
32    # check network status
33    ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline"
34
35    if [ $IP_status == "online" ]; then
36        # check CPU core
37        client_CPU_core=$(ssh -o StrictHostKeyChecking=no $client_IP "cat /proc/cpuinfo |grep processor | wc -l")
38        # check top information
39        ssh -o StrictHostKeyChecking=no $client_IP "top -b -n2 -d1 | awk '/^top/{i++}i==2'" > $drbl_client_top_file
40IP_VM_right_line=""
41        client_idle_CPU=$(cat $drbl_client_top_file | grep ^Cpu | sed 's/^.*ni,//' | sed 's/id,.*$//'  | awk '{print $1}')
42        client_Ram=$(cat $drbl_client_top_file | grep ^Mem | sed 's/total.*$//' | sed 's/^Mem://' | awk '{print $1}')
43        client_unused_Ram=$(cat $drbl_client_top_file | grep ^Mem | sed 's/^.*used,//' | sed 's/free.*$//' | awk '{print $1}')
44   
45    fi
46
47echo "[$client_hostname $client_IP] $IP_status CPU_Core=$client_CPU_core Ram=$client_Ram idle_CPU=$client_idle_CPU unused_Ram=$client_unused_Ram"
48#echo "[$client_hostname $client_IP] $IP_status $client_CPU_core $client_Ram $client_idle_CPU $client_unused_Ram" >> $drbl_client_file
49
50done
51
52# delete tmp file
53rm -f $drbl_client_top_file
Note: See TracBrowser for help on using the repository browser.