Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

closed as off topic by Shane Madden, SvW, John Gardeniers, Ward, GregD Sep 23 '11 at 20:24

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
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! –  hydroparadise 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. –  hydroparadise Sep 23 '11 at 20:31

1 Answer 1

up vote 2 down vote accepted

Instead of:

while [$k -ne $SDATE]

try:

while [ $k -ne $SDATE ]
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.