LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2012, 01:25 AM   #1
davidlt
LQ Newbie
 
Registered: Feb 2011
Posts: 5

Rep: Reputation: 0
Question Forcing utility output in specific locale (LANG=en_US.UTF-8)


I am running my scripts on machines with different locales and at least who produces different dates depending on the locale.

Code:
$ ssh davidlt@machine 'who -s'
davidlt  pts/0        Jan 12 16:54 (empty.lt)

$ who -s
david    console  Jan 13 07:08

$ env -i LANG=en_US.UTF-8 ssh davidlt@lxbuild170 'who -s'
davidlt  pts/0        2012-01-12 16:54 (empty.lt)

$ ssh davidlt@machine 'who -s'
davidlt  pts/0        Jan 12 16:54 (empty.lt)
In the first example SSH send LANG and LC_* variables to the remote machine. So, lt_LT.UTF-8 was set. In the second example the same locale was used on my local machine. On the third example I have tried running a clean environment, which does not have any LANG or LC_* set and setting it myself. Now I got the date I wanted.

Code:
$ LANG=en_US.UTF-8 who -s
david    console  Jan 13 07:08

$ LANG=en_US.UTF-8 bash -c 'who -s'
david    console  Jan 13 07:08

$ LANG=en_US.UTF-8 bash -c 'env' | grep LANG
LANG=en_US.UTF-8

$ env -i LANG=lt_LT.UTF-8 ssh davidlt@lxbuild170 'who -s'
davidlt  pts/0        2012-01-12 16:54 (empty.lt)
Well, after playing more I can see that changing LANG, which also modifies all LC_* does not give any result. Even if variable is set, the default locale is used (lt_LT.UTF-8). The last example illustrates that very well.

It looks like env does the magic forcing command to run in the different locale, but only en_US.UTF-8? But it doesn't work on the local machine commands.

How do I force command to use en_US.UTF-8 locale?

Thanks!
David
 
Old 01-17-2012, 05:59 AM   #2
Jim4Prez
LQ Newbie
 
Registered: Jun 2009
Location: USA
Distribution: Ubuntu
Posts: 1

Rep: Reputation: 0
Instead of passing LANG to the invocation of ssh, pass it as part of the command that you want ssh to run.

pluto@work$ LANG=lt_LT.UTF-8 ssh home 'env'
_=/usr/bin/env
HOME=/home/pluto
LANG=en_US.UTF-8
LOGNAME=pluto
...

pluto@work$ ssh work 'LANG=lt_LT.UTF-8 env'
_=/usr/bin/env
HOME=/home/pluto
LANG=lt_LT.UTF-8
LOGNAME=pluto
...
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Compiling Kernel 2.6.25 with en_US.utf-8? alpha883 Programming 0 04-29-2009 06:08 PM
locale setting, problem with en_US.UTF-8 pru Linux - Software 4 04-18-2008 04:07 AM
Simplified Chinese in Qt apps under en_US.UTF-8? milkycow Slackware 1 05-24-2007 11:05 PM
Help needed with font installation on Debian 3.1 with locale all set to en_US.UTF-8 PhantmShado Linux - Software 1 02-20-2006 03:50 PM
locale is en_US.UTF-8, but gnome turns out to chinese envirement donkey301 Debian 1 03-02-2005 10:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:41 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration