Friday, June 25, 2021

Gotcha of the Day: Fixing AWS Linux setlocal warnings

I'm not sure of the cause, but on a number of occasions various EC2 AWS Linux boxes of mine have started issuing this warning whenever I log in:

-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
-bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

Getting an extra message or two when I log in is fairly benign. However, the same message is triggered whenever a cron job runs. On some of these boxes I've got jobs that run every minute and are usually silent. In these cases, my inbox gets filled with e-mails warning me over and over again that 'LC_ALL' can't change the local to en_US.UTF-8.

Fortunately, the fix is easy. I can ssh to the problematic server and generate the locale by running the following command:

sudo localedef -i en_US -f UTF-8 en_US.UTF-8

Usually, a number of boxes will get hit by this issue at once. In that case, a for loop from the command line fixes them all:

hosts="foo.bar.com baz.bar.com"
foreach h in $hosts; do ssh $h sudo localedef -i en_US -f UTF-8 en_US.UTF-8 ; done

Problem solved.

No comments:

Post a Comment