1

I am executing a script in a crontab that writes a log, when I run it as root, the log is written in spanish.

But when I run it in the crontab, the output is in english.

Is there a way to run the crontab with the same configuration I do when I run it as root?

5
  • 1
    Set the proper LC_* variables. Jan 14, 2022 at 9:59
  • 2
    Does this answer your question? Why is my crontab not working, and how can I troubleshoot it? Jan 14, 2022 at 9:59
  • I can not identify my problem there... Could you please provide me an example? @GeraldSchneider
    – aldegalan
    Jan 14, 2022 at 10:20
  • The problem is that the LC_* variables are unset. How to set them in cron is described in the linked question. Jan 14, 2022 at 10:22
  • Not directly. I decided to write a concrete answer, but mention the general panacea answer and you originally posting it.
    – flowtron
    Jan 14, 2022 at 10:55

1 Answer 1

1

You have two possible solutions; you could write a wrapper script that sets the appropriate enviroment variables and then calls your original cron script. If you want the LANG - which is what I expect you need to set - to be the same for all scripts you just define it at the top of your crontab. This is explained in the answer Gerald Schneider linked Why is my crontab not working, and how can I troubleshoot it? but not explicitely for LC_* or LANG. Here's how to do it:

LANG=es_ES
*/15 */2 3 * * /opt/jobs/repeat-this.sh

Depending on what your script does you may need to set specifc LC_* values; or simply set LC_ALL=es_ES.

LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION, LC_ALL

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .