If I connect via SSH to my Debian 12 Server from another Linux Server and run the who -m command, it displays the following:
test-user pts/1 2024-01-24 11:13 (xx.xx.xx.xx)
But, if I connect from a Windows 11 computer, via Windows Terminal or using a third-party App to connect to the same Debian 12 Server using the same exact user and run the same who -m command, the date/time format display is different.
test-user pts/0 Jan 24 11:15 (xx.xx.xx.xx)
I am running this line in the /etc/profile to determine the IP address from the user on every login, but it doesn't work properly as the output is different and those spaces are altering the outcome.
myip=$(who -m | awk '{print substr($5, 2, length($5) - 2)}')
Is there a way to control the date/time output for the who command? What could be causing this behavior?
Update
Running the locale command from:
From Linux:
$locale
LANG=en_US.UTF-8
LANGUAGE=
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=
From Windows 11
$locale
LANG=
LANGUAGE=
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=
Just to note that this behavior doesn't seem to happen with all the Linux Servers I connect to. It varies and it's explained in the solution below.
As I understood the root cause as per the explanation below, I opted to use the suggestions and they both work for my use case.
$SSH_CONNECTION
instead. – Kamil Maciorowski Jan 24 '24 at 16:14locale
in both cases? Do you get a consistent output withLC_ALL=C who -m
? – Stéphane Chazelas Jan 24 '24 at 17:06Yes, I do.
E.g.
From Linux:
LC_ALL=C who -m test-user pts/1 Jan 24 16:42 (xx.xx.xx.xx)
From Windows 11:
LC_ALL=C who -m test-user pts/0 Jan 24 15:37 (xx.xx.xx.xx)
– User-xdfr1 STS Jan 24 '24 at 20:49locale
, when the value is inside double quotes, that means it is implied. For instance,LC_MESSAGES="en_US.UTF-8"
means that you get theen_US.UTF-8
locale for theLC_MESSAGES
category, but theLC_MESSAGES
environment variable is actually not set, the value is derived from the value ofLANG
(no double quote for that one, so the envvar is set). So in the first case, only LANG is set, and in the second none is set. – Stéphane Chazelas Jan 26 '24 at 16:20