I'm trying to create a script that will assess how many entries per hour are in a log file (/var/log/maillog). The code I have is below:
The lists are abbreviated in the post, but spelled out completely in the script. The innermost command is supposed to get a line count for statements such as
which works when I type it in at the command prompt, but not in the script. Is there something really simple I am missing here?
Code:
#!/bin/bash
for monthname in "Jan" "Feb" "Mar" "Apr" ... "Dec"
do
for daynum in "01" "02" "03" "04" "05" ... "31"
do
for hournum in "00" "01" "02" "03" ... "23"
do
grepstring="\"$monthname $daynum $hournum:\"";
grepresult=`grep $grepstring /var/log/maillog | wc -l;`;
echo "$monthname $daynum $hournum:$grepresult";
done
done
done
Code:
grep "Jan 01 04:" /var/log/maillog | wc -l