I currently have a shell script with a section of code running remote shell commands like so:
grep -v "^[ ]*#" ${CONFIG_FILE} |
while read SERVER USER LOGDIR
do
{
echo "Stats for" $date
echo "${USER}"
echo "iTunes:"
time /bob/shared/ted/remote/rssh ${SERVER} "gzgrep -c \"iTunes Music\" ${LOGDIR}/*${date}*.gz | awk '-F:' '{total+=\$NF}END{print \"Total=\" total}'" 2>&1
echo
echo "Default"
time /bob/shared/ted/remote/rssh ${SERVER} "gzgrep -c \"Default Player\" ${LOGDIR}/*${date}*.gz | awk '-F:' '{total+=\$NF}END{print \"Total=\" total}'" 2>&1
echo
echo "The Rest"
time /bob/shared/ted/remote/rssh ${SERVER} "gzgrep -c \"Junk\" ${LOGDIR}/*${date}*.gz | awk '-F:' '{total+=\$NF}END{print \"Total=\" total}'" 2>&1
} </dev/null 2>&1
done 2>${ERROR_FILE} >${STATS_FILE}
which gives me output like so:
Stats for 20120628
Rich
iTunes:
Total=0
real 0m2.09s
user 0m0.22s
sys 0m0.03s
Default:
Total=0
real 0m2.03s
user 0m0.23s
sys 0m0.00s
The Rest:
Total=0
real 0m2.03s
user 0m0.23s
sys 0m0.00s
Stats for 20120628
Ian
iTunes:
Total=2
real 0m21.44s
user 0m0.22s
sys 0m0.00s
Default:
Total=2
real 0m21.48s
user 0m0.21s
sys 0m0.02s
The Rest:
Total=0
real 0m2.03s
user 0m0.23s
sys 0m0.00s
etc etc…
What I want though is output like this in CSV format:
Rich,0,0,0
Ian,2,2,0
What’s the simplest way to modify the above code to get the output format I require?
Thanks!
I removed the extra echo’s, appended commas and made sure it’s on one line. Try it.
If you don’t want the timing info either, just delete all the
timeinvocations.