Cron job doesn’t seem to work

crondebian-squeeze

I scheduled a task every 5 minutes in my crontab.

The task is well-scheduled by activating the cron log in rsyslog and checked that it executes as planned:

- Right user
- Right command

Sample log entries:

Dec 23 06:40:01 computer /USR/SBIN/CRON[26422]: (myuser) CMD (bash /home/myuser/save.sh &>/home/myuser/cron.log)

I even tried:

Dec 23 06:40:01 computer /USR/SBIN/CRON[26422]: (myuser) CMD (/home/myuser/save.sh &>/home/myuser/cron.log)

Sample crontab command:

*/5 * * * * /home/myuser/save.sh &>/home/myuser/cron.log

The script has the right rights: it can be executed by myuser

Sample script:

#!/bin/sh

HOME_DIR="/home/$USER"
LOGFILE=save.log
DIR_NAME="mydir"
VOLATILE="$HOME_DIR/$DIR_NAME/"
PERMANENT="$HOME_DIR/$DIR_NAME""_storage/"

if [ ! -d "$PERMANENT" ]; then
    mkdir "$PERMANENT"
fi

echo `date +%x\ %X`>$HOME_DIR/$LOGFILE
# Check if both directories actually exist
if [ -d "$VOLATILE" -a -d "$PERMANENT" ]; then
    # Control will enter here if both $VOLATILE and $PERMANENT exist.
    rsync -r -t -v "$VOLATILE" "$PERMANENT">$LOGFILE.output
    echo OK>>$HOME_DIR/$LOGFILE
else
    echo KO>>$HOME_DIR/$LOGFILE
    if [ ! -d "$VOLATILE" ]; then
        echo "Volatile dir does not exist">>$HOME_DIR/$LOGFILE
    fi
    if [ ! -d "$PERMANENT" ]; then
        echo "Permanent dir does not exist">>$HOME_DIR/$LOGFILE
    fi
fi

The command is a bash script which executes properly manually with the same user (even if I copy-paste the exact command executed in cron), but does nothing automatically.

I redirect the script's output in a custom log file to check its execution, which remains empty when the automatic execution happens.

I am totally lost, I dunno what's wrong.

What am I forgetting?

[EDIT] I am using Debian 6 Squeeze

Best Answer

Are you missing a newline on the end of the job, in your crontab?

What does "crontab -l" show?