Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
Show us the cron entry. Which OS are you using ? –  Iain Dec 25 '12 at 6:59
    
Debian Squeeze, I just edited my post –  user573152 Dec 25 '12 at 7:01
    
They're log entries not your cron jobs (from crontab). –  Iain Dec 25 '12 at 7:06
    
We need to see your crontab entry, and if it calls a script, the script itself as well. –  Lipongo Dec 26 '12 at 4:00
    
Cron job + shell script added –  user573152 Dec 27 '12 at 13:27

2 Answers 2

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

What does "crontab -l" show?

share|improve this answer
    
I edited my crontab and added a new line after my task. Now with crontab -l a new line appears before the prompt. Task still doesn't do its job –  user573152 Dec 27 '12 at 14:18

I had the same problem, and i fixed it by removing the "." from the file name. In your case should be:

*/5 * * * * /home/myuser/save &>/home/myuser/cron.log
share|improve this answer
    
You removed more than just the "." from that line... –  Chris S Mar 26 '13 at 12:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.