mercredi 7 janvier 2015

Why does my cronjob not execute my shell-script?


I have a crontab that creates a dump of my database every night:



20 3 * * * /path/to/dailydump.sh


dailydump.sh contains:



#!/bin/sh

DATENAME=`date +%Y%m%d`

BASENAME="/path/to/dumps/db_${DATENAME}.sql"

/usr/bin/mysqldump -hhost -uusername -ppassword databasename > ${BASENAME}


Permissions are:



-rwx---r-x 1 ... dailydump.sh
drwxr-xrwx 2 ... dumps


Why does my cronjob not work?


I'm on a shared server without root access. There are no logs in /var/log/cron or /var/log/syslog. There is not mail in /var/mail/<user_name> or /var/spool/mail/<user_name> (in fact there is nothing at all in /var/mail/ and /var/spool/), MAILTO=my@email.com does not mail any error messages, and 1 2 * * * /path/to/your/command &>/path/to/mycommand.log does not save any log file. ps -ef | grep cron | grep -v grep? returns nothing. (See http://ift.tt/1DAkEZX)


The whole setup worked fine until I moved all files to a new domain and had to setup a new crontab. (Yes, I updated all paths and the database login information. I checked it multiple times, too.) I'm with the same hosting provider on the same machine, so the environment has not changed.


Any help would be greatly appreciated.




"Solution"


Okay, this is most strange. The help center of my provider says that if the script to be executed by a cronjob rests inside a password protected directory, I need to add -auth=user:password -source before the path to the script. So I added that (with the proper authentication). The result was that an error message was emailed to me (so MAILTO= works), telling me /bin/sh: -=: invalid option and listing the available options. So I deleted auth and source again, and now the f%§#ing cronjob runs!!


I have no idea what the problem was, but inserting wrong code and deleting it again did the trick. o_O It appears as if the cronjob actually did run all the time (because if it doesn't, it obviously throws an error), only that it did nothing! Very mysterious. If anyone can explain that to me (in a reproducible manner), I'll offer a bounty of 200 and award it (after the necessary wait of two days).


Thank you to everyone for your help. I learned a lot again (although not what was wrong here).



Aucun commentaire:

Enregistrer un commentaire