Python and cron jobs.

Steven Taschuk staschuk at telusplanet.net
Tue Aug 5 18:27:22 EDT 2003


Quoth Fazer:
  [...]
> Actually, I think I will open the crontab file as a file and do the
> changes that way because this would also involve in the deletion of
> some cronjobs.  [...]

Note that you can invoke the crontab so as to print out a given
user's crontab:
    crontab -u username -l
Using the os.popen family, you can then read the output as a file,
modify it, then write it back as the stdin for an invocation of
    crontab -u username

This is perhaps slightly more work than simply manipulating the
file in /var/cron/tabs directly; certainly it is less efficient,
though I doubt that's much of a concern for this task.  The
advantage is that it allows for the possibility that the local
system has some strange way of storing crontabs, a way which
crontab(1) understands but your program should not need to.

> [...] I just wish to know how to get the cron deamon to
> reload the crontab.  Are you certain that it checks for changes or
> reloads every minute?

No.  There's lots of cron implementations, and I certainly haven't
used all of them; perhaps some need a SIGHUP to reload, for
example.  Check your local documentation to be sure, 'man 8 cron'
or what have you, and/or just try it as Michael suggested.

-- 
Steven Taschuk                staschuk at telusplanet.net
"I tried to be pleasant and accommodating, but my head
 began to hurt from his banality."   -- _Seven_ (1996)





More information about the Python-list mailing list