Posts Tagged locale

Relation between TortoiseSVN and locale

The other day, I got stuck on a problem with TortoiseSVN for about half a day! 😯
Yes, I know, it is a pretty long time to get a simple subversion client working…

The error I was continuously getting was:

Network connection closed unexpectedly

Nothing else! Nothing in the log files on both the client and the server. πŸ™
The funny thing is that it was working perfectly fine using a command line client or even Eclipse Subversive.

After a (too) long time of investigation, I noticed that I was getting the following warnings when I was running the following command line directly on the server:

$ svn list svn+ssh://smoreau@localhost/data/svn/
svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LANG is en_US.UTF-8
svn: warning: please check that your locale name is correct
smoreau@localhost's password:
svnserve: warning: cannot set LC_CTYPE locale
svnserve: warning: environment variable LANG is en_US.UTF-8
svnserve: warning: please check that your locale name is correct
branches/
tags/
trunk/

Actually, any svn command was triggering the warning messages:

$ svn info
svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LANG is en_US.UTF-8
svn: warning: please check that your locale name is correct

Could it possibly be related with my TortoiseSVN problem?
Because I didn’t have any other idea, I decided to give it a go. πŸ˜‰

It appears that these warning messages came from a configuration problem around the locale package on the server. Indeed, look what we get if we run the locale command:

$ locale -a
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_COLLATE to default locale: No such file or directory
C
POSIX

After some more investigation, it looks like this problem appeared when I upgraded the version of the locale package via APT. πŸ˜•

Once again, I asked my friend Google to help me out. It suggested me the following solutions:

  • Run locale-gen en_US.UTF-8Didn’t work
  • Run update-locale LANG=en_US.UTF-8Didn’t work
  • Run dpkg-reconfigure localesWORKED πŸ˜€

In conclusion, I wasn’t able to use TortoiseSVN because of a configuration problem on the locale package after an upgrade… Does it make sense? πŸ™„

, , ,

No Comments

Locale settings for your cron job

Do you get special characters problem when executing your bash script from a cron job?
And does the same script work fine when it is directly executed from the command line?
If yes, continue reading this article! πŸ˜‰

The reason of this characters problem is probably because of your locale settings.
Indeed, If you try to run the command locale from the command line and from a cron job, you may get different results such as:

From the command line From a cron job
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
LANG=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=

As you can see, the cron job is not using UTF-8. That must be the problem! πŸ™‚

So the question now is how to change the locale settings for the cron job?
Some people say that you need to add the following environment variables to the crontab entry:

SHELL=/bin/bash
LANG=en_US.UTF-8
LANGUAGE=en
LC_CTYPE=en_US.UTF-8

But this actually didn’t work for me. πŸ™

What you can do instead is create (if not already present) the file /etc/environment and add the following line:

LANG=en_US.UTF-8

The cron process will read this file when it starts, so you need to restart it in order to apply the change:

service cron restart

Hope this will fix your characters problem. πŸ˜‰

, , , , ,

18 Comments