Ich habe hier ein seltsames Problem mit meinen Cronjobs.
Ich möchte ein Python-Script einmal pro Stunde ausführen lassen.
Also habe ich mittels
crontab -e
meine crontab bearbeitet.
Sie sieht nun folgendermaßen aus:
45 * * * * /home/user/script.py
Danch habe ich noch den cron-Daemon neugestartet:
sudo /etc/init.d/cron restart
Leider wird das Script nicht ausgeführt. ☹
Auch ein
45 * * * * script.py
hilft nichts.
Egal wo das Script liegt, entweder im home-Verzeichnis oder in z.b. /usr/local/bin führt es cron nicht aus.
Die Rechte müssten passen, ich hab ein
sudo chmod a+x script.py
gemacht.
Von der Kommandozeile aus funzt das Script ohne Probleme.
Hier mal das Script:
#!/usr/bin/python # # download_clouds.py ver. 1.1 # # Download coulds map for xplanet from a random mirror, optionally # save the one to archive directory. # # Usage: # python download_clouds.py - to save the output as clouds_2048.jpg # python download_coulds.py output.jpg - to save the output as output.jpg # # (C) 2004 Michal Pasternak <michal@pasternak.w.lub.pl> # # This file is in public domain. # user-tunable parameters: # how often to download the image? maxDownloadFrequencyHours = 3 # how many times to retry if download fails (each time tries using a # different mirror) maxRetries = 3 # default filename of the output file (in current directory). You can # specify it on the command line defaultOutputFile = "/home/user/wallpaper/clouds_2048.jpg" # archive dir - where to save old files? archiveDir = None # "/usr/public/cloudsArchive" # The list of mirrors. Add new ones here. mirrors = [ "http://xplanet.sourceforge.net/clouds/clouds_2048.jpg", "ftp://mirror.pacific.net.au/pub2/xplanet/clouds_2048.jpg", "http://xplanet.fortha.org/clouds_2048.jpg", "http://www.ruwenzori.net/earth/clouds_2048.jpg", "http://xplanet.dyndns.org/clouds/clouds_2048.jpg", "http://userpage.fu-berlin.de/~jml/clouds_2048.jpg", "http://rcswww.urz.tu-dresden.de/~es179238/clouds_2048.jpg", "http://home.megapass.co.kr/~jhkim1101/cloud_data/clouds_2048.jpg", "http://user.chol.com/~winxplanet/cloud_data/clouds_2048.jpg", "http://home.megapass.co.kr/~gitto88/cloud_data/clouds_2048.jpg", "http://myhome.hanafos.com/~hyoungkee/cloud_data/clouds_2048.jpg", "http://giga.forfun.net/clouds_2048.jpg", "http://php.nctu.edu.tw/~ijliao/clouds_2048.jpg", "http://www.wizabit.eclipse.co.uk/xplanet/files/mirror/clouds_2048.jpg", "http://www.wizabit.eclipse.co.uk/xplanet/files/local/clouds_2048.jpg", "ftp://ftp.iastate.edu/pub/xplanet/clouds_2048.jpg", "http://enekoalonso.com/projects/xplanet/clouds_2048.php", "http://xplanet.nerp.net/clouds_2048.php" ] # end of user-tunable parameters import random, urllib, sys, stat, time, os # set output file name try: outputFile = sys.argv[1] except: outputFile = defaultOutputFile pass # check if the file exists and is old enough to overwrite try: s = os.stat(outputFile) mtime = s[stat.ST_MTIME] fs = s[stat.ST_SIZE] found = True except: mtime = 0 fs = 0 found = False pass if time.time() - mtime < maxDownloadFrequencyHours * 3600 and fs > 400000: sys.stderr.write("File is already up to date!\n") sys.exit(0) else: if found and archiveDir is not None: # archivize old file import shutil archName = os.path.join(archiveDir, time.strftime("%Y-%m-%d_%H-%I") + "_" + os.path.basename(outputFile)) sys.stderr.write("Archivizing old file to %s...\n" % archName) shutil.move(outputFile, archName) pass pass # ok, download: for a in range(maxRetries): try: url = mirrors [ random.randint(0, len(mirrors)-1) ] sys.stderr.write("Using %s\nDownloading...\n" % url) urllib.urlretrieve(url, outputFile) break except: pass pass
Beim Neustart des cron-Daemons kommen keine Fehlermeldungen!
Habe eben beim Schreiben dieses Posts festgestellt, dass nun das Script ausgeführt wird! Es liegt nun unter /usr/local/bin
Leider wird das heruntergeladene jpg nicht in /home/user/wallpaper gespeichert!?
Ich weiß jetzt leider auch nicht woran das liegt.
Ein
grep -i cron /var/log/syslog
bringt folgendes:
Jan 6 12:50:01 ubuntu /USR/SBIN/CRON[13027]: (user) CMD (download_clouds.py) Jan 6 12:55:01 ubuntu /USR/SBIN/CRON[13178]: (user) CMD (download_clouds.py) Jan 6 13:00:01 ubuntu /USR/SBIN/CRON[13324]: (user) CMD (download_clouds.py)
Scheint also alles i.O zu sein.
Ich bin jetzt halt ein bisschen ratlos!
Im Verzeichnis /home/user/wallpaper befindet sich keine clouds_2048.jpg, d.h. das Script müsste mindestens einmal die Datei herunterladen, wie gesagt von der Kommandozeile funktionierts ja.
Gruß
elzed