Posts Tagged unicode characters not working in bash cron

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

3 Comments