System: Xubuntu 13.10When I have this crontab entry*/5 * * * * cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junkjunk has a byte size of 0.Running$ cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junkgives a file with a proper size and content.
Why does redirection in crontab result in a zero byte file?
shell;cron;io redirection
The probem because cron run task with sh. &> is a shortcut to redirect both stderr and stdout to the same file in bash, not in sh.In sh, your command:cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junkmeaning run two commands separately:Run cat /home/dbk/.bash_aliases in backgroundcat /home/dbk/.bash_aliases &Truncate the junk file.> /home/dbk/Desktop/junkSo you should use bash to run your command in crontab:*/5 * * * * bash -c cat /home/dbk/.bash_aliases &> /home/dbk/Desktop/junkor using more portable way:*/5 * * * * cat /home/dbk/.bash_aliases > /home/dbk/Desktop/junk 2>&1