Operating System - HP-UX
1753964 Members
7484 Online
108811 Solutions
New Discussion юеВ

Re: using tail -f in a script

 
SOLVED
Go to solution
Hamdy Al-Sebaey
Regular Advisor

Re: using tail -f in a script

Hi Robert,

What about,for example
tail -50 /var/adm/syslog/syslog.log > /tmp/robert.
regards,
Hamdy
Thanks for sharing knowledge
John Poff
Honored Contributor

Re: using tail -f in a script

Hi,

My example is messed up. I can't write shell scripts until I get enough caffeine into my system!

Christian's awk example will do the job.

JP
john korterman
Honored Contributor
Solution

Re: using tail -f in a script

Hi again,
sounds strange. I have just tried this:

1) created a logfile
# touch /tmp/dunavent

2) made the script dunavent.sh with this content:
#!/usr/bin/sh
LOGFILE=/tmp/dunavent
tail -1f $LOGFILE | while read line
do
echo $line | grep e
if [ "$?" = "0" ]
then
# found
echo $line >>./log_Y
fi
done

3) executed dunavent.sh in the background:
# dunavent.sh &

4) added lines to /tmp/dunavent
# echo "ee and e" >>/tmp/dunavent

And all lines containing "e" are added to log_Y
(!?)
How did you do it?

regards,
John K.

it would be nice if you always got a second chance
Jean-Louis Phelix
Honored Contributor

Re: using tail -f in a script

Hi,

Here is a shell which does it without a daemon :

#!/usr/bin/sh
tail -f log_X |&
NPID=$!
while :
do
read -p VAR
echo $VAR | grep n > log || continue
kill $!
break
done
cat log

Regards,

Jean-Louis.
It works for me (┬й Bill McNAMARA ...)

Re: using tail -f in a script

John K:

Your script did the trick for me!!! Thanks!!

-cd