[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: who: sorted output + minor usage change
From: |
Pádraig Brady |
Subject: |
Re: who: sorted output + minor usage change |
Date: |
Mon, 09 Feb 2015 21:27:52 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
On 09/02/15 19:52, Assaf Gordon wrote:
> Hello Pádraig,
>
> On 02/09/2015 05:49 AM, Pádraig Brady wrote:
>> On third thought, perhaps we should tweak the output from who to be more
>> easily processed?
>> It seems like small tweaks could improve things a lot, and would be a more
>> general solution.
>
> Agreed.
> though I don't know if the output of 'who' is commonly used with automated
> parsing, and thus expected not to change?
Given the awkwardness of parsing,
I doubt changes to add placeholders would impact anything significant.
>> The time field can already be sorted with `sort -b -k3,4` (we should remove
>> the locale variant)
>
> This could be a bit problematic depending on the options used.
> For example, with "-a", I get the following on my system:
> ====
> $ ./src/who -a
> system boot 2015-02-02 17:24
> run-level 2 2015-02-02 17:24
> LOGIN tty4 2015-02-02 17:24 1901 id=4
> LOGIN tty5 2015-02-02 17:24 1905 id=5
> LOGIN tty2 2015-02-02 17:24 1914 id=2
> gordon - tty3 2015-02-06 16:46 old 12643
> LOGIN tty6 2015-02-02 17:24 1919 id=6
> gordon - tty1 2015-02-04 19:53 old 6103
> gordon ? :0 2015-02-02 17:24 ? 4694 (:0)
> gordon + pts/0 2015-02-02 17:28 . 5894 (:0)
> gordon + pts/12 2015-02-02 17:28 old 5894 (:0)
> gordon + pts/16 2015-02-05 10:49 00:04 5894 (:0)
> pts/17 2015-02-04 20:53 24776 id=s/17 term=0
> exit=0
> pts/26 2015-02-06 22:08 0 id=/26 term=0
> exit=0
> pts/27 2015-02-04 17:03 0 id=/27 term=0
> exit=0
> ====
> So the third and fourth fields (determined by whitespace) are not always the
> login time.
Right. So we'd have placeholders for empty fields.
'.' for NAME (to match solaris)
'.' for the -T column as previously discussed
'-' for the IDLE column (so not clashing with "." there
> Also noticed that in POSIX locale, the time string must be "%b %e %H:%M" (in
> the example above, the locale was en_US.UTF-8, and the time string was
> "%Y-%m-%d %H:%M") - so there's another white space in POSIX locale.
Oh right, POSIX states to use "%b %e ...".
That's still quite processable, though a little more awkward to sort on that
field.
> But since my original intention was to simply find "logged in users sorted by
> idleness",
> I guess using this can be assumed to always work:
> $ LC_ALL=C who -u | sort -b -k6,6
Yes that should work reliably.
I'll look about adding placeholders so that who -a is processable.
thanks!
Pádraig.