Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a backup script which I need to run at a particular time of a day so I am using cron for this task and from within cron am also trying to redirect the output of backup script to a logfile.

crontab -e

*/1 * * * * /home/ranveer/backup.sh &>> /home/ranveer/backup.log

In the above cron entry I am redirecting both stderr and stdout to a log file.

The above cron job executes fine according to syslog and it performs the task mentioned in the backup.sh file but it doesn't write anything to the log file.


Oct 19 20:26:01 ranveer CRON[15214]: (ranveer) CMD (/home/ranveer/backup.sh &>> /home/ranveer/backup.log)

When I run the script from cli it works as required and output is written to a log file

ranveer@ranveer:~$ ./backup.sh &>> backup.log 
ranveer@ranveer:~$ cat backup.log
Fri Oct 19 20:28:01 IST 2012
successfully copied testdir
test.txt successfully copied

So, why the output of file is not getting redirected to the file from within cron.

share|improve this question
up vote 41 down vote accepted

I solved the problem. There are two ways:


Change the redirection from &>> to 2>&1. So now crontab -e looks like

*/1 * * * * /home/ranveer/vimbackup.sh >> /home/ranveer/vimbackup.log 2>&1

I believe the above works because by default cron is using sh to run the task instead of bash so &>> is not supported by sh.


Change the default shell by adding SHELL=/bin/bash in the crontab -e file.

share|improve this answer
cron is like sh: it doesn't pick out a single program. There are many implementations. The most prevalent implementation is Vixie cron. I am the (current, not the original) author of another. I believe that most cron daemons will use the system's sh, but that can vary in whether it accepts &>>. Some cron daemons (like mine) don't enable you to change which shell executes the cron lines with SHELL=... lines in the crontab. I'm glad you found a solution that works for you; just thought it was worth pointing out there are many variables that could affect whether it works for others. – dubiousjim Oct 19 '12 at 15:50
@dubiousjim: Thanks. valuable info. – RanRag Oct 19 '12 at 16:09
How to insert YYYY-MM-DD_hh-mm-sec into output file name, so that every file name is different and kept without rewriting? – Danijel Jan 11 at 13:18
@Danijel : This should help serverfault.com/questions/117360/… – RanRag Jan 15 at 9:09

Your Answer


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.