#!/bin/sh # 01/18/04 Large and small pings, .csv logfile # 01/20/04 Parm 1 is host name, optional parm2 echoes ping to console # 02/03/04 Reduced minimum largelong and smalllong to 1000 ms # Function to ping a host and log the result pinglog () { timestamp=$(date --iso-8601=minutes | cut -b 1-16) # YYYY-MM-DDThh:mm-0800 timestamp=$(echo $timestamp | sed s/"T"/","/) ping -c 4 -s 1024 $1 | grep from > $tempfile largecount=$(cat $tempfile | grep -c from) largelong=$(cat $tempfile | grep -c \=[1-9][0-9][0-9][0-9]\.[0-9]) if [ $parms -gt 1 ] then touch $tempfile # In case all pings fail cat $tempfile fi ping -c 4 $1 | grep from > $tempfile smallcount=$(cat $tempfile | grep -c from) smalllong=$(cat $tempfile | grep -c \=[1-9][0-9][0-9][0-9]\.[0-9]) #smalllong=$(cat $tempfile | grep -c \=[1-9][0-9][0-9]\.[0-9]) # 100 ms if [ $parms -gt 1 ] then touch $tempfile # In case all pings fail cat $tempfile fi rm --force $tempfile if [ -e $logfile ] # If log file exists then #echo "Name... Date..... Time LgCt,LgLn,SmCt,SmLn (s/b 4,4,0,0)" echo $1","$timestamp","$largecount","$smallcount","\ $smalllong","$largelong | tee -a $logfile else echo "Name,Date,Time,LgCt,LgLn,SmCt,SmLn" | tee $logfile echo $1","$timestamp","$largecount","$smallcount","\ $smalllong","$largelong | tee -a $logfile fi } # Function to get a MAC address's signal strength and log the result scanlog () { iwlist wlan0 scan \ | grep -A 2 $1 \ | grep Quality \ | cut --delim="-" --fields=2 \ | sed 's/Noise level://g' \ | tee -a $log } # Main program remountrw # Make logfile writeable let parms=$# tempfile="/var/log/z$1.tmp" logfile="/usr/local/bin/pingscan.csv" #ip_name_mac=$(gethost $1) #mac=$(echo $ip_name_mac | cut --delim=' ' --fields=3) #echo $mac $1 #scanlog $mac pinglog $1 exit