LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 04-05-2011, 05:54 AM   #1
jmvidalvia
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Rep: Reputation: 0
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!
 
Old 04-05-2011, 07:28 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,116

Rep: Reputation: 218Reputation: 218Reputation: 218
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.
 
Old 04-06-2011, 01:19 AM   #3
jmvidalvia
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Guttorm View Post
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..
 
Old 04-06-2011, 02:55 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,116

Rep: Reputation: 218Reputation: 218Reputation: 218
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.
 
Old 04-06-2011, 04:37 AM   #5
jmvidalvia
LQ Newbie
 
Registered: Mar 2011
Posts: 23

Original Poster
Rep: Reputation: 0
That was great: thanks a lot!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab - redirecting script output - question laki47 Linux - Newbie 3 10-19-2009 09:12 AM
Crontab/Shell Output problem mdx34 Linux - Newbie 5 09-12-2008 04:31 PM
Strange output log of crontab kuangchen Linux - Newbie 1 05-30-2008 04:13 AM
Bash Sleep vs crontab and bash serial port nutthick Programming 4 06-01-2006 02:42 AM
Directing xosd output to X display from crontab BWebb Linux - General 3 06-30-2005 01:09 PM


All times are GMT -5. The time now is 01:29 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration