alecxs
alecxs

Reputation: 741

follow logfile with tail and exec on event

i wonder if there is a more simplyfied way to run the tail -f or -F on a logfile and execute a command each time a special keyword is mentioned.

this is my working solution so far, but i don't like it for following reasons:

example:

#!/sbin/sh
while [ 1 ]
  do
    tail -n1 logfile.log | grep "some triggering text" && mount -v $stuff >> logfile.log
done

i tried the following but grep won't give return code until the pipe break

#!/sbin/sh
tail -f -n1 logfile.log | grep "some triggering text" && mount $stuff

i am running a script on android which is limited to
busybox ash

edit:
the problem is related to grep. grep won't give return code until the last line. what i need is return code for each line. maybe kind of a --follow option for grep, or sed, awk, or a user defined function which works with tail --follow

Upvotes: 0

Views: 336

Answers (0)

Related Questions