LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Bash+crontab output is in different language (http://www.linuxquestions.org/questions/linux-general-1/bash-crontab-output-is-in-different-language-873071/)

jmvidalvia 04-05-2011 06:54 AM

Bash+crontab output is in different language
 
Hi!
I am running this script, that sets the begining and end of a period:
Code:

#!/bin/bash
MES=`head -n 1 /home/jm/Dropbox/par/mes`
YR=`head -n 1 /home/jm/Dropbox/par/yr`
MES_NUM=`date +"%m"`
MES_TXT=`date -d "$YR-$MES-01" +%^b`
HOY=`date +"%d-%^b-%Y"`
INI=`date +"01-$MES_TXT-$YR"`
ULT=`echo $(cal $MES $YR) | awk '{print $NF}'`

if [ "$MES" = "$MES_NUM" ]
then FIN=$HOY
else FIN=`date +"$ULT-$MES_TXT-$YR"`
fi

echo $INI > /home/jm/sh/mysql/ini
echo $FIN > /home/jm/sh/mysql/fin

If I run it by myself, the variables INI and FIN are created in spanish, which I need, eg 01-ABR-2011.
But, when I run the script through crontab (obviously with the same user), the output is created in english!, eg 01-APR-2011.
My locale are set as follows,
Code:

LANG=es_ES.UTF-8
LC_CTYPE="es_ES.UTF-8"
LC_NUMERIC="es_ES.UTF-8"
LC_TIME="es_ES.UTF-8"
LC_COLLATE="es_ES.UTF-8"
LC_MONETARY="es_ES.UTF-8"
LC_MESSAGES="es_ES.UTF-8"
LC_PAPER="es_ES.UTF-8"
LC_NAME="es_ES.UTF-8"
LC_ADDRESS="es_ES.UTF-8"
LC_TELEPHONE="es_ES.UTF-8"
LC_MEASUREMENT="es_ES.UTF-8"
LC_IDENTIFICATION="es_ES.UTF-8"
LC_ALL=

Is there anything I am missing?
Thanks!

Guttorm 04-05-2011 08:28 AM

Hi

Cron doesn't read the files where the locale is set. Why not simply copy all that locale stuff to the beginning of your script? If a script needs a specific locale to work properly, I think the script should set it, and not rely on some other system settings.

jmvidalvia 04-06-2011 02:19 AM

Quote:

Originally Posted by Guttorm (Post 4314474)
Hi

Cron doesn't read the files where the locale is set. Why not simply copy all that locale stuff to the beginning of your script? If a script needs a specific locale to work properly, I think the script should set it, and not rely on some other system settings.

Thanks Guttorm,
I am afraid it didn't work: adding my locale into the script doesn't change the output, which is still in english..
:(

Guttorm 04-06-2011 03:55 AM

Hi

I think you will need to use export in the script. I just made this little script and put it in cron:
Code:

#!/bin/bash
export LANG=es_ES.UTF-8
date >/tmp/date.spanish

After letting it run, the file "/tmp/date.spanish" was in Spanish.

jmvidalvia 04-06-2011 05:37 AM

That was great: thanks a lot!


All times are GMT -5. The time now is 05:15 AM.