-1

here is the script I wrote but it seems it has problem ! I want to print the last X days of a log file ! and here I assume that X is 5 to later generate it ! please help !

for d in \
 $(sed -nre 's/.*\[(..)\/(...)\/(....):(..:..:..) .*/\1 \2 \3 \4/p' thttpd.log | date `+%s -f-);`
do echo $d >s1; done

time=$(expr 60 \* 60 \* 24 \* 5)
EDATE=`tail -1 s1`
SDATE=$[$EDATE - $time]
time=$(expr 60 \* 60 \* 24 \* 5)
EDATE=`tail -1 s1`
SDATE=$[$EDATE - $time]
k=`tail -1 s1`
echo $k
echo $SDATE
while [$k -ne $SDATE](k and SDATE contain numbers)
 do
k=`tail -1 s1`
sed '1d' < s1 > tempfile
mv s1 s1.old
mv tempfile s1
echo $K| awk '{print strftime("%d/%m/%Y:%T",$1)}'|tee -a ass

done
matarsak
  • 37
  • 5
  • Well, first off, you don't tell us what error you're getting if any. Second, `sed -i '1d' s1` will delete the first line of s1 without needing all that tempfile stuff. Finally, telling us what you want this to **DO** would help us greatly. – DerfK Sep 23 '11 at 19:56
  • I'm actually confused ! I'm working on a script that supposed to print the last X days from a log file ! and i worked with 5 as an example to later on generate it . I convert the dates to epoch time , then I subtract 5 days from it which gives me the starting date that should be printed ! and now I should print dates from starting date till the end ! – matarsak Sep 23 '11 at 20:04
  • Explanation points everywhere could lose points! – Chad Harrison Sep 23 '11 at 20:14
  • @hydroparadise Umm, you mean exclamation points? – EEAA Sep 23 '11 at 20:19
  • @ErikaA Supposed to be a play on words because he didn't explain himself very well. I tired. – Chad Harrison Sep 23 '11 at 20:31

1 Answers1

2

Instead of:

while [$k -ne $SDATE]

try:

while [ $k -ne $SDATE ]
unhappyCrackers1
  • 977
  • 1
  • 6
  • 18