Real time log file redirect

Hi all,

i would like to write the shell script program, it can monitor the access_log "real time"

when the access_log writing the line contain "abcdef" the program will be "COPY" this line into a file named "abcdef.txt", do the same thing if the contain "123456" "COPY" it into a file named "123456.txt"

how can i do it in real time?

can i use "tail -f"?

many many thx

Yes:

nohup tail -f access.log|while IFS= read -r;do
	case $REPLY in
		(*abcdef*)printf "%s\n" "$REPLY">>abcdef.txt;;
     		(*123456*)printf "%s\n" "$REPLY">>123456.txt;;
	esac
done &

hi Radoulov,

Thank you for your kindly reply^^:b:

i would like to add the function to archive the log daily, can i do it like this?
but is not working, is it the "IF" statement is out of the "WHILE" loop ?

======================================================================
previousDay=`date --date "1 days ago" "+%Y%m%d"`
nowTime=`date "+%H%M%S"`

nohup tail -f access.log|while IFS= read -r;do
case $REPLY in
(*abcdef*)printf "%s\n" "$REPLY">>abcdef.txt;;
(*123456*)printf "%s\n" "$REPLY">>123456.txt;;
esac
if [ $nowTime == 000000 ]; then
mv abcdef.txt abcdef.txt."$previousDay"
mv 123456.txt 123456.txt."$previousDay"
fi
done &

I would schedule another job to move the logs on a regular basis.