Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

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

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 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 At IU, how do I get support for Linux or Unix?

This is document aeek in domain all.
Last modified on October 21, 2008.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.