Last change
on this file since 195 was
195,
checked in by rock, 14 years ago
|
Add function Code: check_drbl_client.sh (Detect DRBL clinet status)
|
-
Property svn:executable set to
*
|
File size:
1.8 KB
|
Rev | Line | |
---|
[195] | 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 | |
---|
| 11 | source /opt/drbl-virt/conf/drbl-virt.conf |
---|
| 12 | source $Work_Path/functions_drbl_virt |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | # [Varliables] |
---|
| 16 | client_IPs=$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $1}') |
---|
| 17 | drbl_client_file="/tmp/drbl_client_status.$$" |
---|
| 18 | drbl_client_top_file="/tmp/drbl_client_top.$$" |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | # [Main] |
---|
| 22 | for client_IP in $client_IPs |
---|
| 23 | do |
---|
| 24 | # local variables |
---|
| 25 | client_hostname="$(cat $Work_Home/etc/IP_HOST_TABLE | grep -v "#" | awk '{print $2}')" |
---|
| 26 | IP_status="online" |
---|
| 27 | client_CPU_core="" |
---|
| 28 | client_Ram="" |
---|
| 29 | client_idle_CPU="" |
---|
| 30 | client_unused_Ram="" |
---|
| 31 | # check network status |
---|
| 32 | ping -c1 -w1 $client_IP > /dev/null 2>&1 || IP_status="offline" |
---|
| 33 | |
---|
| 34 | if [ $IP_status == "online" ]; then |
---|
| 35 | # check CPU core |
---|
| 36 | client_CPU_core=$(ssh -o StrictHostKeyChecking=no $client_IP "cat /proc/cpuinfo |grep processor | wc -l") |
---|
| 37 | # check top information |
---|
| 38 | ssh -o StrictHostKeyChecking=no $client_IP "top -b -n1" > $drbl_client_top_file |
---|
| 39 | client_idle_CPU=$(cat $drbl_client_top_file | grep ^Cpu | sed 's/^.*ni,//' | sed 's/id,.*$//' | awk '{print $1}') |
---|
| 40 | client_Ram=$(cat $drbl_client_top_file | grep ^Mem | sed 's/total.*$//' | sed 's/^Mem://' | awk '{print $1}') |
---|
| 41 | client_unused_Ram=$(cat $drbl_client_top_file | grep ^Mem | sed 's/^.*used,//' | sed 's/free.*$//' | awk '{print $1}') |
---|
| 42 | fi |
---|
| 43 | |
---|
| 44 | echo "$client_hostname $client_IP $IP_status CPU_Core=$client_CPU_core Ram=$client_Ram idle_CPU=$client_idle_CPU unused_Ram=$client_unused_Ram" |
---|
| 45 | echo "$client_hostname $client_IP $IP_status $client_CPU_core $client_Ram $client_idle_CPU $client_unused_Ram" >> $drbl_client_file |
---|
| 46 | |
---|
| 47 | done |
---|
| 48 | |
---|
| 49 | |
---|
Note: See
TracBrowser
for help on using the repository browser.