Crontab and Unicode Characters


Crontab in Linux likes to keep its own shell environment and this can really cause frustrating problems with output of your cron jobs if they don’t get fixed as its too much ironic to see not the same behiviour of your shell scripts when they are run in crons than to what you normally see in a bash.

I was running a script that included a few of other scripts and it was not showing unicode characters properly when it ran as in a cron. Solution is to include ‘export LANG=en_US.UTF-8′ in your shell script but the ideal way to do so I found was to pass on this environment variable directly in command parameter of a cron job.

The unicode character that was missing earlier ‘degree‘ symbol became visible as soon as I added the variable LANG=en_US.UTF-8 to crontab’s command.

# crontab -l
MAILTO=""
57 9 * * * LANG=en_US.UTF-8 /root/back/hdd-report/report

  1. #1 by David on May 13, 2010 - 9:22 PM

    Hi,
    Thanks for this tip! I ran into this problem and I was banging my head against the wall.

    After repeatedly forgetting the crontab syntax, I decided to write a crontab GUI. Feel free to check it out – http://www.corntab.com

    Cheers!

  2. #2 by Abbas on May 13, 2010 - 9:30 PM

    Glad it helped.
    The way you integrated the crontab syntax generation into a simple but interactive web application is really marvellous. Your creativeness is really appreciated :D Thanks for sharing, David :)
    Cheers.

  3. #3 by kaushal on August 11, 2010 - 7:14 AM

    got solved my prob..
    thanks for posting it

(will not be published)