How to display the output of “WHO” command and along with count?

Asked By 0 points N/A Posted on -
qa-featured

As we know " who" command in unix gives output as:

abc pts/0 Aug 23 10:43 …

bcd pts/2 Aug 23 10:43 …

but i want to see the output as :

abc pts/0 Aug 23 10:43 …

bcd pts/2 Aug 23 10:43 …

Total number of users: 2

Please help me to get this output.

SHARE
Best Answer by KevinBlythe
Best Answer
Best Answer
Answered By 0 points N/A #111483

How to display the output of “WHO” command and along with count?

qa-featured

You should consult unix or linux guides on how to create and run shell scripts as it is too lengthy to discuss here.

Write the following in a shell script:

—- start —-

who
echo -n " Number of  users:"
who | awk '{ print $1 }' | sort | uniq | wc -l

—- end —-

The first line prints out the standard "who" command output.  The second line displays the text "Number of users: ".  The "-n" option to echo prevents it from inserting a newline character.  Finally, the third line counts the number of unique users from the output of a "who" command.

Hope this helps.

 

Related Questions