Linux – Redirect cronjob STDOUT and STDERR to /dev/null not working

cronlinuxredirectstderrstdout

I'm baffled as to why this isn't working.

I've tried redirecting STDOUT and STDERR using "&>" and also "2>&1" and neither seems to work. I still get e-mailed by this cron job (every minute!) with smbclient complaining that there are no files in the share.

* * * * * smbclient //scanner/scan-import secretpass -U administrator -c "prompt; mget *; del *" &> /dev/null

For the curious: A client has an old and expensive scanner that scans multiple documents at high speed–but the software has no way to configure the save location. They don't want the documents saved directly on the old XP workstation, so I've shared out the save location and use this cron job to automatically pull the documents over to their linux server.

Best Answer

Bash supports redirecting stdout and stdin together using &>, but sh does not. Cron used the Bourne shell (sh) rather than Bash. Use >/dev/null 2>&1 instead.