LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script from cron (https://www.linuxquestions.org/questions/programming-9/bash-script-from-cron-137381/)

kubla 01-22-2004 03:18 AM

bash script from cron
 
Dear All,

I'm having a problem with a shell script.

The script tails syslog and on a specific event, launches another script passing it the contents of the syslog line:

#!/bin/bash

tail -f /var/log/syslog | while read line ; do if
echo $line | grep --quiet RRQ ; then /home/kubla/shellscripts/dhcp_watch/process_log.php "$line";
fi ; done

This works perfectly launched from shell.

However, I need this script to always run and after logrotate it loses its handle on syslog and while still running according to the process list, it doesn't respond any more.

My thought was to create a cronjob that would run 1 minute after logrotate, kill any instances of the script that are running and call the script again. This works but the script continues not to respond to events.

Is there something obvious I'm missing?

Thanks in advance.

kubla 01-22-2004 03:19 AM

I should add, I have confirmed that all the paths in all the scripts are correct.

misaka 01-22-2004 03:35 AM

Re: bash script from cron
 
Quote:

Originally posted by kubla
However, I need this script to always run and after logrotate it loses its handle on syslog and while still running according to the process list, it doesn't respond any more.

The best way to fix this is to modify how you use tail. If you're using GNU's tail, it should support the cmdline option '--follow=name', this should prevent it from losing it's file handle/descriptor on the syslog file when the logs get rotated. Check your local manpage to be sure this option is followed.

As a side note, if you happen to be using a BSD-flavoured tail, '-F' appears to do the same thing.


--Misha

kubla 01-22-2004 04:30 AM

Thanks misaka.

That's done the trick.

I've modified the tail line to read:

tail --follow=name /var/log/syslog | while read line ; do if

and it works a treat!

Cheerz


All times are GMT -5. The time now is 04:19 PM.