Redirecting the output of a cron job

前端 未结 3 1795
梦如初夏
梦如初夏 2020-12-24 14:55

I have the following entry in crontab:

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


        
相关标签:
3条回答
  • 2020-12-24 15:08

    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'
    
    0 讨论(0)
  • 2020-12-24 15:10

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

    0 讨论(0)
  • 2020-12-24 15:13

    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'
    
    0 讨论(0)
提交回复
热议问题