Python and cron jobs.

F

Fazer

Hello,

I am wondering that if it is possible to add cron jobs via a web or
shell interface? I can make Python act as a shell script and be
called by a PHP script. But my main goal here is to be able to manage
cronjobs. Add or remove certain crjob jobs etc...

Can any kind soul shed some light on how I would accomplish this?

Thanks,

Faizan
 
L

Lee Harr

Hello,

I am wondering that if it is possible to add cron jobs via a web or
shell interface? I can make Python act as a shell script and be
called by a PHP script. But my main goal here is to be able to manage
cronjobs. Add or remove certain crjob jobs etc...

Can any kind soul shed some light on how I would accomplish this?


I think adding them from the shell is probably the "normal" way.
For adding cron jobs from the web, you might look at webmin.

Basically, the crontab is just a file, so if you can edit the file
from your program and then force cron to reload the crontab you
are all set.
 
F

Fazer

Lee Harr said:
I think adding them from the shell is probably the "normal" way.
For adding cron jobs from the web, you might look at webmin.

Basically, the crontab is just a file, so if you can edit the file
from your program and then force cron to reload the crontab you
are all set.


Thanks for your reply.

I thought that crontab was directory? I don't require webmin, I need
a script that would add the cron job and possible force the cron to
reload as you said. Do you know how may I accomplish this?
 
F

Fazer

Lee Harr said:
I think adding them from the shell is probably the "normal" way.
For adding cron jobs from the web, you might look at webmin.

Basically, the crontab is just a file, so if you can edit the file
from your program and then force cron to reload the crontab you
are all set.

Hmm...nevermind. I just found out that it is a file. How would I
reload the crontab?
 
S

Steven Taschuk

Quoth Fazer:
I am wondering that if it is possible to add cron jobs via a web or
shell interface? I can make Python act as a shell script and be
called by a PHP script. But my main goal here is to be able to manage
cronjobs. Add or remove certain crjob jobs etc...

Can any kind soul shed some light on how I would accomplish this?

The question is a bit vague, I'm afraid.

If you just want to know how to invoke crontab(1) from a Python
script, look up os.popen() and friends in the standard library
documentation. As for getting the cron daemon to reload the
changed crontab, that's a nop in the crons I've seen; they check
for changes every minute anyway.

If you want to know something else, please specify.
 
F

Fazer

Steven Taschuk said:
Quoth Fazer:

The question is a bit vague, I'm afraid.

If you just want to know how to invoke crontab(1) from a Python
script, look up os.popen() and friends in the standard library
documentation. As for getting the cron daemon to reload the
changed crontab, that's a nop in the crons I've seen; they check
for changes every minute anyway.

If you want to know something else, please specify.

Hello and thanks for your reply!

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. 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?
 
F

Francois Pinard

[Fazer]
I just wish to know how to get the cron deamon to reload the crontab.

You could stop and restart the deamon (the same as for any other deamon).
There is also a `crontab' program, for which there is a `man' page.
 
S

Steven Taschuk

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.
 
C

Christos TZOTZIOY Georgiou

[...] 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.

Interfacing through the crontab executable should suffice for every cron
out there...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top