I want to do something:
Alex
new_name at mit.edu
Sat Jul 28 12:01:14 EDT 2001
If you're on unix, you might want to have a look at cron, which is
perfect for this kind of thing. Here's something I wrote for a friend
this week that describes roughly how to use it:
#!/usr/bin/env python
"""Check that apache is running on the local machine, and restart it,
if not.
After copying this script, making it executable, and configuring the
path to the httpd binary, and the port the server is running on, run
the command 'crontab -e' from the command line. Within the editor
that this command opens, add a line like
0-59 * * * * /path/to/this/script.py
For instance, this is what my crontab file looks like:
######################################################################
SHELL=/bin/tcsh
PATH=/bin:/usr/bin:/scratch2/alex
MAILTO=alex_c at mit.edu
# run-parts
0-59 * * * * ~/Public/check_cuckoo.py
0 3 * * * ~/python/databases/backup_scripts/backup4.py
# 30 3 * * * ~/python/network/python_cvs.py
# Kill anything older than a week
30 6 * * * /usr/bin/find /scratch2/backups/ -atime +7 | xargs rm -f
30 6 * * * /usr/bin/find ~alex_c/.group-backups/ -atime +7 | xargs rm -f
"""
import urllib, os
# Path to the httpd binary
httpd_path = '/scratch/www/bin/httpd'
port = 8080
try: root_page = urllib.urlopen('http://localhost:%i' % port)
except IOError:
# Couldn't reach the web page. Try restarting the server.
assert os.system(httpd_path) == 0
HTH,
Alex.
More information about the Python-list
mailing list