Anyone know a better way to do this were it is faster? This currently is slow when pushing high lines per second to this script:
#!/bin/bash
declare -A clientarray
file=$1
timer=$2
e=$(date --date "now +$timer second" +%s)
while read line
do
if [ -n "${clientarray[$line]}" ]; then
let "clientarray[$line]=clientarray[$line]+1"
echo "$line: ${clientarray[$line]}"
elif [ -z "${clientarray[$line]}" ]; then
clientarray[$line]=1
echo "$line: ${clientarray[$line]}"
fi
if [ $(date +%s) -gt $e ]; then
e=$(date --date "now +$timer second" +%s)
fi
done < <(tail -F $file | gawk -F"]" '/]/ {print $1}')
Here is an example of the lines:
someline]
someline2]
somethingidontwant
someline3]
somethingelseidontwant
someline4]
and to call the script:
bash script.sh somelogfile.log 1
If I comment out the if logic at the very end it goes really fast but with it the speed drops 2/3rds. Tested it with pv:
(this is with the if logic):
ubuntu@myhost:~/graphs$ tail -F somelogfile.log | pv -N RAW -lc >/dev/null |
> bash script.sh somelogfile.log 1 | pv -N SCP -lc >/dev/null
RAW: 2.18k 0:00:16 [ 493/s ] [ <=> ]
SCP: 593 0:00:16 [ 150/s ] [ <=> ]
(this is without)
ubuntu@myhost:~/graphs$ tail -F somelogfile.log | pv -N RAW -lc >/dev/null |
> bash script.sh somelogfile.log 1 | pv -N SCP -lc >/dev/null
RAW: 7.69k 0:00:15 [512/s] [ <=> ]
SCP: 7.6k 0:00:15 [503/s] [ <=> ]
Let me know if I am missing something on my script or testing side, especially any "DOH!"'s. I think at this point I would love one =)