appended crontab entries with py script

R

rbt

How can I safely append a crontab entry to a crontab file
progammatically with Python?

I need to handle crontabs that currently have entries and crontabs that
are empty. Also, I'd like this to work across Linux and BSD systems.

Any pointers?
 
M

Mike Meyer

rbt said:
How can I safely append a crontab entry to a crontab file
progammatically with Python?

Well, one way would be to invoke the system crontab utility and use an
"editor" that passes the file to your program, and reads the results
back.
I need to handle crontabs that currently have entries and crontabs that
are empty. Also, I'd like this to work across Linux and BSD systems.

Any pointers?

I think most Free Unix systems use the Vixie cron, and the non-free
ones have a "crontab" command (do some of them call it cron?) with the
same API. So you're pretty safe using that.

If you want to assume that you're going to have the vixie cron, you
could dig into it's guts to see what it does for locking, and do that
by hand.

<mike
 
R

rbt

Well, one way would be to invoke the system crontab utility and use an
"editor" that passes the file to your program, and reads the results
back.


I think most Free Unix systems use the Vixie cron, and the non-free
ones have a "crontab" command (do some of them call it cron?) with the
same API. So you're pretty safe using that.

If you want to assume that you're going to have the vixie cron, you
could dig into it's guts to see what it does for locking, and do that
by hand.

<mike

Here's what I did... can you write uglier code than this ;)

Works on Mac and Linux... for the most part.

def add_cron_entry():
home = os.path.expanduser('~')
cur_cron = os.popen('crontab -l > current_crontab.txt')
cur_cron.read()
cur_cron.close()
fp = file('current_crontab.txt', 'a')
print >> fp, "0 * * * * %s/.theft_recovery.py" %home
fp.close()
load = os.popen('crontab current_crontab.txt')
load.read()
load.close()
 
R

rbt

I have a win32 service written in Python. It works well. It sends a
report of the status of the machine via email periodically. The one
problem I have is this... while trying to send an email, the script
loops until a send happens and then it breaks. Should it be unable to
send, it sleeps for 10 minutes with time.sleep(600) and then wakes and
tries again. This is when the problem occurs. I can't stop the service
while the program is sleeping. When I try, it just hangs until a reboot.
Can some suggest how to fix this?

Thanks,
rbt
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top