LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   change "who" command output (https://www.linuxquestions.org/questions/linux-newbie-8/change-who-command-output-571860/)

khairilthegreat 07-24-2007 07:37 AM

change "who" command output
 
Hi all

Is it possible to change the who command otput.

The output of who command in my box is:

khairil@serverwarkom:~$ who
khairil :0 2002-01-03 01:01
root pts/1 2007-07-24 19:32 (152.118.99.49)

It says that there is 2 user online. Khairil and root. We can also conclude that khairil connect locally and root connect remotely from IP 152.118.99.49.

Is it possible to change the output of the command. For example the output will be

khairil@serverwarkom:~$ who
khairil :0 2002-01-03 01:01
root :0 2007-07-24 19:32

or something similar thet do not tell any user where is the root connect from.

rocket357 07-24-2007 08:28 AM

As a quick and dirty fix, you could alias "who" to "who -q".

Code:

alias who='who -q'
This will list just the names of the users logged in without listing any ip's or hostnames.

You'll have to apply this globally to affect your users.

khairilthegreat 07-25-2007 12:45 AM

alisaisng who
 
Thanks rocket 357.

It'sa good solution. Is there enaything else that will work?

b0uncer 07-25-2007 12:55 AM

Good solution, except that if anybody checks what "who" actually does, it's revealed that it's an alias and then if anybody just used
Code:

which who
and started 'who' from that directory, for example with (I'm not sure at all it's in /bin/, not on Linux atm)
Code:

/bin/who
the output would be again the default one (with ip addresses).

A slightly more complex option would be to wrap the actual 'who' into a script so that regular users could not start 'who', but could start the script that started 'who -q' - the original 'who' would of course be moved to another place, and this script put into it's place, so people would run the script by typing 'who' and not the actual 'who'. Shortly: script in place of real 'who', that runs 'who -q' from someplace else - with users forbidden to use the original executable from where ever it is.

binary_pearl 07-25-2007 01:03 AM

You could try doing something like this:

who | sed -e 's/pts\/[0-9]\{1,\}/:0/'

This should replace pts/* with :0.

You may also want to check out the commands "w" and "finger" and "last". These commands may also contain the terminal information that you are trying to hide.

--Shaun

khairilthegreat 07-26-2007 02:36 AM

Thanks
 
Thank you all. I'll combine b0uncer and binary_pearl tips.

I think that's the solution i need.


All times are GMT -5. The time now is 06:49 AM.