script sorted list of logged in users

script sorted list of logged in users

am 15.04.2008 01:08:33 von robusto33

Hi, I have a quick question about a script. I'm using the command
"who" and "sort" to create a list of a sorted, logged-in users that
belong to a certain group. Can anyone help me make a script that will
show a list of ONLY the usernames of the logged in users? I've been
trying for hours and can't get it to display what I want.

Re: script sorted list of logged in users

am 15.04.2008 05:23:21 von Maxwell Lol

robusto33@gmail.com writes:

> Hi, I have a quick question about a script. I'm using the command
> "who" and "sort" to create a list of a sorted, logged-in users that
> belong to a certain group. Can anyone help me make a script that will
> show a list of ONLY the usernames of the logged in users? I've been
> trying for hours and can't get it to display what I want.

a quick and dirsty version is
who | awk '{print $1}' | sort|uniq

This one uses 2 processes instead of 4:

who | awk '!a[$1]++ {print $1}'

Re: script sorted list of logged in users

am 15.04.2008 20:25:39 von Dan Stromberg

On Mon, 14 Apr 2008 23:23:21 -0400, Maxwell Lol wrote:

> robusto33@gmail.com writes:
>
>> Hi, I have a quick question about a script. I'm using the command
>> "who" and "sort" to create a list of a sorted, logged-in users that
>> belong to a certain group. Can anyone help me make a script that will
>> show a list of ONLY the usernames of the logged in users? I've been
>> trying for hours and can't get it to display what I want.
>
> a quick and dirsty version is
> who | awk '{print $1}' | sort|uniq

I like this method, actually, though sometimes you can use "sort -u" to
eliminate a fork+exec. However, I once saw a bug in GNU sort -u.

> This one uses 2 processes instead of 4:
>
> who | awk '!a[$1]++ {print $1}'

awk is fine I guess, but I'm not sure this particular awk method works.

In this case it's probably not true, but in some cases (especially for
large inputs) a pipeline may actually run faster than a monolithic
process if you get decent parallelism out of the pipeline. This is
probably going to become more and more true as multicore processors catch
on.