I have a bash script that parses log files - aggregating data in an AWK array - that takes part of the file path as a parameter. It runs fine, I can run multiple instances in the background manually. The trouble is I can't figure out how to avoid invoking the script manually for each parameter in my list.
Depending on where I've put the &
it either runs the instances serially or tries to run all the jobs at once (I don't want to see a load average of 9999 again).
script.sh param1 &
script.sh param2 & ... #works fine
script.sh < params.txt & ... #runs serially
Placing &
at various places within the script had some undesirable outcomes.
hub=$1
while read date; do
zgrep ^1 /logarchive/http/${hub}pr*/$date*.gz|\
awk -F'[ ,]' '{print$34,$(NF-6),$6,$(NF-7)}'|\
awk 'NR>1{bytesDown[$1 " " $2] += $3; bytesUp[$1 " " $2] += $4} END {for (i in bytesDown) print i, bytesDown[i], bytesUp[i]}'\
> ${hub}.$date.txt
done < dates.txt
I'd like to run an instance in the background for each parameter in a file.