Today is: 9 January, 2012
Check todays hot topics

Statistics gathering in one line and 30 seconds REVISED

This is my revision to Statistics gathering in one line and 30 seconds. Stripped and sanitized.

#!/bin/bash
 
LOG_PATH="" # Leave this empty if you wish to be prompted for it
USERNAME="" # Leave this empty if you wish to be prompted for it
HOSTS=(web1.example.com web2.example.com web3.example.com)
 
echo -n "Enter the search criteria: "
read PATTERN
 
if [ -z $LOG_PATH ]
then
        echo -n "Enter log path: "
        read LOG_PATH
fi
 
if [ -z $USERNAME ]
then
        echo -n "Enter the username to log in with: "
        read USERNAME
fi
 
for index in ${HOSTS[@]}
do
        echo -n "${index}: "
        ERRCOUNT=$(ssh ${USERNAME}@${index} "grep -i${PATTERN} ${LOG_PATH} | wc -l ")
        NOERRCOUNT=$(ssh ${USERNAME}@${index} "grep -v -i ${PATTERN} ${LOG_PATH} | wc -l ")
        PERCENT=$(echo "(${ERRCOUNT} / (${ERRCOUNT} + ${NOERRCOUNT})) * 100" | bc -l)
        echo "${ERRCOUNT} / ${NOERRCOUNT} / ${PERCENT:0:5}%"
done

AttachmentSize
calc.sh771 bytes