ARCHIVED: In Unix, how do I see if my friends or colleagues are logged into the same Unix machine as I am?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

You can check to see if particular users are logged into your Unix machine in two ways.

The tcsh watcher special variable

If you are using tcsh (also known as TC-shell), you can set the watch special variable to monitor logins and inform you when users you specify log into or out of the system.

To use the watch variable, you must change your shell to tcsh. For help, see ARCHIVED: In Unix, what is chsh, and how do I use it to change my shell?

The format for setting the watch variable is as follows. Enter this line at the Unix shell prompt if you want it active only during the current login session, or add it to your .cshrc file if you want it always to be active:

  set watch="# user1 any user2 any user3 any)

Replace # with a number in minutes. This indicates how often the system will check for user logins (the default is ten minutes). Replace user1, user2, and user3 with the usernames of users you want to monitor (you can monitor more than three usernames). Do not substitute anything for any unless you are looking for a specific tty. Make sure that all the parameters in the watch variable are contained on a single line.

When you have a watch set, the system checks for new logins and logouts at the interval you specified, and then reports to you the next time you enter a command or press Enter at the shell prompt. Alternately, if you enter log at the Unix shell prompt, the system will immediately return a report.

For more information, consult the tcsh man page. Enter the following command at the Unix shell prompt:

  man tcsh

Creating an alias with grep and w

You can create an alias (the example used is "friends") that will tell you when friends and colleagues are logged in by using the Unix commands w and grep. Use w to list all users logged into the Unix system, piping the output into grep, which can then find usernames in the output. You can use any shell except sh for this.

First, create a file named .friends in your home directory containing the usernames of accounts you are interested in monitoring, one per line.

Then, if your shell is ksh (Korn Shell) or bash (Bourne-again shell), place the following line in your .profile:

  alias friends="w | grep -f ~/.friends"

If you use csh (C-shell) or tcsh (TC-shell), place the following line in your .cshrc:

  alias friends w | grep -f ~/.friends

The friends command will become available after you log out and back in, or re-source your initialization files.

For more information, enter any of the following commands at the Unix prompt:

  man who
  man w
  man grep

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

This is document aeek in the Knowledge Base.
Last modified on 2018-01-18 09:23:18.