![]() ![]() |
mapstats |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/sh# (c)2003 by Jan Krupa (krupaj@mobilnews.cz)# http://www.mobilnews.cz/honza/# Changes by Jirka Klir (Unreal][) for Mapstats v3.0 AJAX. http://www.jklir.net# -- Configuration ---------------------------------------------------# Mapstats directorySTATS_PATH=/var/www/www.kobylisy.czf/mapstatscd $STATS_PATH# Program pathsPING_PATH=pingNMAP_PATH=nmapFPING_PATH=fping# STATS_TYPE - ping, fping or nmapSTATS_TYPE=ping# Don't change anything bellow this line if you are not sure what# you are doing ;)# --------------------------------------------------------------------for LINE in `ls -1 $STATS_PATH_DATA | grep .nodes`; doa_file=`echo $LINE | awk -F. '{ printf "%s", $1 }'`file_comp=$STATS_PATH/$a_file.nodesfile_state=$STATS_PATH/$a_file.stateprintf "" > $file_state# Get computer statesif [ $STATS_TYPE = "fping" ]; thenping_host_all=""for LINE in `cat $file_comp`; doping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`ping_host_all="${ping_host_all} ${ping_host}"done$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_statefiif [ $STATS_TYPE = "ping" ]; thenfor LINE in `cat $file_comp`; doping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`;ping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`;if [ "$ping_lat" = ";" ]; thenping_lat=\;`$PING_PATH -c 1 -w 2 $ping_host | grep rtt | awk -F\ '{ printf "%s", $4 }' | awk -F\/ ' { printf "%s", $2 }'`;fiif [ "$ping_lat" = ";" ]; thenecho "$ping_host;0;0" >> $file_stateelseecho "$ping_host;1$ping_lat" >> $file_statefidonefiif [ $STATS_TYPE = "nmap" ]; thenping_host_all=""for LINE in `cat $file_comp`; doping_host=`echo -n $LINE | awk -F\; '{ printf "%s", $5 }'`ping_host_all="${ping_host_all} ${ping_host}"done$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_statefidone