Redirecting the output of a cron job Redirecting the output of a cron job unix unix

Redirecting the output of a cron job


Your redirection order is incorrect. Stderr is not being redirected to the file, but is being sent to stdout. That's what you must be receiving in your mail.

Fix the redirection by changing your cron job to:

0 5 * * * /bin/bash -l -c'export RAILS_ENV=my_env;cd /my_folder;./script/my_script.rb > ./log/my_log.log 2>&1'


Try swapping 2>&1 with > ./log/my_log.log.


Judging by this answer you just need to switch the order of the redirects:

0 5 * * * /bin/bash -l -c 'export RAILS_ENV=my_env; cd /my_folder; ./script/my_script.rb > ./log/my_log.log 2>&1'