473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

appended crontab entries with py script

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?
Sep 13 '05 #1
3 5380
rbt <rb*@athop1.ath.vt.edu> writes:
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
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Sep 14 '05 #2
rbt
On Tue, 2005-09-13 at 23:18 -0400, Mike Meyer wrote:
rbt <rb*@athop1.ath.vt.edu> writes:
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


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()

Sep 14 '05 #3
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

Sep 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Arkascha | last post by:
Maybe someone can give me a short help with this... I got a server application in a LAMP environment doing batch tasks. A cronjob serves as a regular trigger, a metronom. The trigged...
4
by: David Bruno | last post by:
I set up a crontab using cpanel8 for the first time. It's just to run a very simple php script that sends an email and has one include() function. The first try at the crontab produced a...
3
by: Frank R. Suchy | last post by:
Hi, I want a php-script to maintain (some of) "my" cron jobs. Therefore it has to modify some crontab.txt (no problem) and has to execute crontab. But since php runs as the apache-user it...
2
by: David Garamond | last post by:
I was thinking on how one would design an optimal (performance-wise) database of large number of schedules with crontab-like semantic. There will potentially be hundreds of thousands or even...
3
by: Sandman | last post by:
I have a PHP cli script, that backups my databases, using mysqldump via system(). When logged in with SSH, and launching the script with "./backup.php", all works just as it should, but when I...
4
by: Chr1s | last post by:
How do I execute a crontab command using php (not CLI) as user Joe? I don't have any problem getting output from commands such as 'ls' using passthru and exec but I am stumped with crontab. ...
2
by: martijn | last post by:
H! I have made a program that is checking if a program is running or not. If the program is not running then it must start the program again. in the /etc/crontab: * * * * ...
0
by: Martin Marcher | last post by:
Hello, is anyone aware of a crontab library. Possibly even more complete, something that will let me create/manipulate/delete crontab entries in a nice way and install the new crontab...
3
by: xtremebass | last post by:
Hi , I am want to run the shell script to run every 10 minutes of interval ,so that i have used crontab command for scheduling the shell script .. it cant works . i have checked wall command in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.