Solved cronjob and locale

Hello there,

I have a python script that does something with the files. In user profile I've set locale to UTF-8, since some filenames/folders use special characters (other language than ENG). When I run script under the user profile, everything is working fine, but when I run it under the cronjob, the script fails with error "UnicodeEncodeError: 'utf-8' codec can't encode characters in position 37-38: surrogates not allowed".

So the question here is, is it possible to change locale for cronjob to UTF-8 for the duration when the script is running?

Locale settings for user:
LANG=sl_SI.UTF-8
LC_CTYPE="sl_SI.UTF-8"
LC_COLLATE=C
LC_TIME="sl_SI.UTF-8"
LC_NUMERIC="sl_SI.UTF-8"
LC_MONETARY="sl_SI.UTF-8"
LC_MESSAGES="sl_SI.UTF-8"
LC_ALL=


Thanks
 
I've never had this problem, but since cron does use sh(1) by default you would just need to set the locale in the cron file, something like:

export LANG=sl_SI.UTF-8

EDIT: I least this is what I do when I need some diferent PATH in a cron job. Alternatively, you could set that inside the script.
 
Back
Top