LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-22-2004, 03:18 AM   #1
kubla
LQ Newbie
 
Registered: Jan 2004
Posts: 11

Rep: Reputation: 0
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.

Last edited by kubla; 01-22-2004 at 03:19 AM.
 
Old 01-22-2004, 03:19 AM   #2
kubla
LQ Newbie
 
Registered: Jan 2004
Posts: 11

Original Poster
Rep: Reputation: 0
I should add, I have confirmed that all the paths in all the scripts are correct.
 
Old 01-22-2004, 03:35 AM   #3
misaka
LQ Newbie
 
Registered: Jan 2004
Distribution: Debian
Posts: 1

Rep: Reputation: 0
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
 
Old 01-22-2004, 04:30 AM   #4
kubla
LQ Newbie
 
Registered: Jan 2004
Posts: 11

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script using /etc/cron.hourly to execute cron.php file? rioguia Programming 3 06-11-2008 08:09 AM
bash script & cron probs. skubik Programming 17 10-16-2005 02:00 PM
cron bash script troubles zzyzx Slackware 3 04-12-2005 12:27 PM
PPPD Script problem when cron-scheduling the script andresurzagasti Linux - Networking 0 11-24-2004 02:54 PM
webmin,cron and bash login script colesen Linux - Software 0 08-12-2003 07:36 PM


All times are GMT -5. The time now is 09:53 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration