Sunday, 29 January 2012

who


who
who  gives information regarding the users logged in the system, terminals, the  client IP addresses,the start and end times of previous logins and  their other  command  details. It s output is different from that of finger  command. “who” can give the  old details of users processes which  finger cannot


Example 1)
To know the details of users currently logged in a machine,  along with the header, use  who  command  with  –Hu.

home/kamlesh$who   -Hu
Name        Line                Time              Activity          PID                Hostname
kamlesh     pts/0       Jan 07 23:07    15:25        5206202             (169.173.25.64)
yadav         pts/1       Jan 08 07:40     0:22         3735576              (169.8.25.100)
stella          pts/2       Jan 08 14:47     0:35         5124214              (169.8.25.114)
jaffer          pts/5       Jan 08 16:17      .               4108396              (169.8.25.100)


Name
            Identifies the user's login name.
   
Line  
            Identifies the line name as found in the /dev directory. It is actually the terminal number  of   the user.

 Time
            Represents the time when the user logged in.
     
 Activity
            Represents the hours and minutes since activity last occurred on that user's line. A . (dot) here       indicates line activity within the last minute. If the line has been quiet more than 24 hours or has not been used since  the last system startup, the entry is marked as old.
     
 PID
            Identifies the process ID of the user's login shell.
    
 Hostname
            Indicates the name of the machine the user is logged in from.


Example2)
Who command gets the  information from  /etc/utmp file. If you wish it to use another file, specify the  filename  after who.

To get the output  from    /var/adm/wtmp.

home/kamlesh $who  -Hu    /var/adm/wtmp
Name                    Line                      Time                Activity                  PID              Hostname
kamlesh               pts/2                Dec 28 00:26                .                   930160        (indra)
sneha                  pts/2                  Dec 28 01:09                .                  156080        (indra)
krishna                pts/1                  Dec 28 02:33                .                  660214        (169.8.25.100)
krishna                pts/2                  Dec 28 02:37                .                  942618        (169.8.25.117)
justin                   pts/2                   Dec 28 02:51               .                 934590        (169.154.25.65)
varsha                 pts/2                  Dec 28 03:02                 .                  672308        (indra)
jaffer                   pts/2                   Dec 28 04:27               .                  267016        (169.8.25.100)
steve                  pts/3                    Dec 28 05:33               15:16           610818        (indra)
..
..
^c

All such  old sessions are displayed . so to keep a track on people who logged in and out ,the command helps.

Example 3)
To know the details of your  current session , ie the session from which you are running the command , an easier to remember command is used

home/kamlesh $ who am i
kamlesh    pts/1       Jan 08 01:30     (169.173.25.64)


Example 4)
In multi user work  environments, you may  require to know  whether your colleague is   logged in from a remote machine or  check continuously  whether  he/she has logged in ,
 Here is a script to do that.

#!/usr/bin/ksh
while [ 1 ]
do
who|grep  10.120.245.60
if [ $? -eq 0 ]
then
      while [ 1 ]
      do
      echo "\a Logged in"
      sleep 1
      done
fi
echo "Not logged in yet"
sleep 5
done



No comments:

Post a Comment