jablonka.czprosek.czf

mapstats

Subversion Repositories:
[/] [gen_mapstats] - Blame information for rev 5

 

Line No. Rev Author Line
11unreal#!/bin/sh
2 
3# (c)2003 by Jan Krupa (krupaj@mobilnews.cz)
4# http://www.mobilnews.cz/honza/
5# Changes by Jirka Klir (Unreal][) for Mapstats v3.0 AJAX. http://www.jklir.net
6 
7# -- Configuration ---------------------------------------------------
8# Mapstats directory
9STATS_PATH=/var/www/www.kobylisy.czf/mapstats
10 
11cd $STATS_PATH
12 
13# Program paths
14PING_PATH=ping
15NMAP_PATH=nmap
16FPING_PATH=fping
17 
18# STATS_TYPE - ping, fping or nmap
19STATS_TYPE=ping
20 
21# Don't change anything bellow this line if you are not sure what
22# you are doing ;)
23# --------------------------------------------------------------------
24 
25for LINE in `ls -1 $STATS_PATH_DATA | grep .nodes`; do
26 a_file=`echo $LINE | awk -F. '{ printf "%s", $1 }'`
27 
28 file_comp=$STATS_PATH/$a_file.nodes
29 file_state=$STATS_PATH/$a_file.state
30 
31 printf "" > $file_state
32 # Get computer states
33 if [ $STATS_TYPE = "fping" ]; then
34 ping_host_all=""
35 
36 for LINE in `cat $file_comp`; do
37 ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`
38 ping_host_all="${ping_host_all} ${ping_host}"
39 done
40 $FPING_PATH -e $ping_host_all | awk -F\ '{ printf "%s;", $1; if ($3=="alive") printf "1;%s\n", substr($4, 2, (length($4)-1)); else printf "0;0\n"; }' > $file_state
41 fi
42 
43 if [ $STATS_TYPE = "ping" ]; then
44 for LINE in `cat $file_comp`; do
45 ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`;
46 
47 ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`;
48 if [ "$ping_lat" = ";" ]; then
49 ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`;
50 fi
51 
52 if [ "$ping_lat" = ";" ]; then
53 echo "$ping_host;0;0" >> $file_state
54 else
55 echo "$ping_host;1$ping_lat" >> $file_state
56 fi
57 done
58 
59 fi
60 
61 if [ $STATS_TYPE = "nmap" ]; then
62 ping_host_all=""
63 
64 for LINE in `cat $file_comp`; do
65 ping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`
66 ping_host_all="${ping_host_all} ${ping_host}"
67 done
68 
69 $NMAP_PATH -vnsP $ping_host_all | awk -F\ '{ if ($1=="Host") { if (match($2, /\(/) == 0) { printf "%s", $2; } else { printf "%s", substr($2, 2, (length($2)-2)); } if ($6=="up.") printf ";1;-\n"; else printf ";0;-\n"; } }' > $file_state
70 fi
71 
72done

Powered by WebSVN 2.2.1