[lug] Automatic removal of cron job by cron script
karl horlen
horlenkarl at yahoo.com
Fri Nov 2 17:32:33 MDT 2007
Thanks Mike and Ken
I should have thought of this. Easy enough and fine
for what I need to do.
Since this post is out there. If anyone has
suggestions for removing the job from cron, have at
it. I'm curious how it might be done.
--- "Michael J. Hammel" <mjhammel at graphics-muse.org>
wrote:
> On Fri, 2007-11-02 at 16:10 -0700, karl horlen
> wrote:
> > I've created a cron job script called 'monitor'
> that
> > monitors the health of a hardware component. When
> an
> > error is detected, I want this script to:
> >
> > 1) Call another script called 'alert' to send a
> > repeating error message (using an endless loop
> with
> > sleep 2) to the console as an alert for staff.
> > 2) Remove the original cron JOB (remove the entry
> from
> > the crontab file from within the original cron
> script
> > 'monitor') versus just killing the actual running
> > script 'monitor'. If I don't remove the job, it
> will
> > keep spawning more 'monitor' processes and I will
> have
> > only killed the last process.
>
> I would think you'd want to have the alert send
> messages for as long as
> the error is detected, up until the error is
> cleared. This would simply
> be a matter of using a single script with multiple
> modes. The monitor
> script always monitors (re: always runs under cron)
> and each time an
> error is found it sends the message. It would
> continue to run as a cron
> job. When the error is cleared it would stop
> sending alert messages.
>
> Alternatively, if you really want the monitor to not
> run and just let
> the alert keep running, then just put a config file
> that the monitor
> script updates before it starts the alert script.
> If it sees the config
> file (it exists at all) then it doesn't do anything.
> Cron keeps calling
> monitor, but because the config file is there it
> doesn't do anything.
> If you do launch alert and have it run indefinitely
> then you'll want to
> exec() it so monitor can exit and cron can complete
> that particular
> cycle. That will leave alert running as a child of
> init, however.
>
> These two methods are easier than trying to modify
> the cron config from
> within a running cron job.
>
> --
> Michael J. Hammel
> Senior Software Engineer
> mjhammel at graphics-muse.org
> http://graphics-muse.org
>
------------------------------------------------------------------------------
> "In the republic of mediocrity, genius is
> dangerous."
> Robert S. Ingersoll, American lawyer and politician
> (1833-1899).
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List:
> http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667
> channel=#colug
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the LUG
mailing list