Issues with echo commands?
I run this script as quanta suggest me
#!/bin/bashEDATE=$(tail -1 a | awk '{ print substr($4, 2, length($4)) }')
EEPOCH=$(date -d "$(echo "$EDATE" | awk 'BEGIN { FS = "[/:]"; } \
{ print $1" "$2" "$3" "$4":"$5":"$6 }')" +%s)
time=$(expr 60 \* 60 \* 24 \* 5)
SEPOCH=$(expr $EEPOCH - $time)while read line
do
DATE=$(echo $line | awk '{ print substr($4, 2, length($4)-1) }' | \
awk 'BEGIN { FS = "[/:]"; } { print $1" "$2" "$3" "$4":"$5":"$6 }')
DEPOCH=$(date -d "$DATE" +%s)
[[ $DEPOCH -ge $SEPOCH && $DEPOCH -le $EEPOCH ]] && echo $line | \
awk '{ print substr($4, 2, length($4)) }' >> as1
done < a
I checked that and it seems that your script want to check log file line by line. Since it has more than 14000 items it takes a lot. So when I run it the cursor goes to next line and next line and I should press it 14000 times so that the whole log file be checked! It’s impossible! It just work for short log file I think. Is the problem because of while?
This one liner (I’ve split it for clarity) should give you the same result. You can optionally add > as1 to the end to redirect the output to a file. Put the path to the apache log file where I’ve put <logfile>
for d in \
$(sed -nre 's/.*\[(..)\/(...)\/(....):(..:..:..) .*/\1 \2 \3 \4/p' <logfile> | date +%s -f-);
do echo $[ $d - 86400 * 5]; done
The date command doesn’t need an explicity UTC formatted date for the -dargument, although it doesn’t understand dates as the apache logs output them, so I’ve done some substitution to swap the slashes and the colon separating the date and time with spaces.
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
- Windows File Permissions and Attributes
- What is the easiest way to upgrade my existing Perl 5.14 to Perl 5.16 on FreeBSD 9 using the ports system?
- Know if mysql has done its job
- Redirect https .com to https .co.uk without a valid SSL cert on .com without DNS change
- Why is it a bad idea to use customer email as from address





