Re: Date Format of Shell Program Changes in Apache

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This isn't a perl list, but I was playing around and found you can do this in perl:

#!/usr/bin/perl
use strict;
BEGIN
{
    $ENV{LC_TIME}    = 'en_US.UTF-8';
}
print "content-type: text/plain\n\n";
print `who`;
print `locale`;


Hopefully that helps,

- Y

On Fri, Jul 1, 2016 at 5:50 PM, Yehuda Katz <yehuda@xxxxxxxxxx> wrote:
This is because of the locale settings. I changed the script to show the locale (and to be plain text so the spaces are visible).

#!/usr/bin/perl
use strict;
print "content-type: text/plain\n\n";
print `who`;
print `locale`;

Apache shows this:

yehuda   pts/2        Jul  1 17:37 (pool-xxxxxx.washdc.fios.verizon.net)
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=

And the command line shows this:

content-type: text/plain
 
yehuda   pts/2        2016-07-01 17:37 (pool-xxxxxx.washdc.fios.verizon.net)
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=


The environment variable that sets how the time is shown is LC_TIME.
You can probably change this in your script (for example, php provides a way, perl likely has one too) and there is a third-party module that claims to set the locale for the whole server.
Your OS might also give you a way to set it for the whole server.

- Y


On Fri, Jul 1, 2016 at 4:34 PM, Rob McAninch <rob.mcaninch@xxxxxxxxx> wrote:
Server version: Apache/2.4.10 (Debian)

This seems like it should be simple but manual pages and searching have not shown me an answer yet. Reduced it to as simple as I can, I don't understand why the date format is different in each.

#!/usr/bin/perl
use strict;
print "content-type: text/html\n\n";
print `who`;


When I call it up in a web browser I get

rob pts/1 Jul 1 12:28 (192.x.x.x)

The same script on a command line via ssh I get:

prompt$ perl tryme.cgi
content-type: text/html

rob      pts/1        2016-07-01 12:28 (192.x.x.x)



--
Rob



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux