The "who" agent


* Description

The who agent creates a child agent which migrates from machine to machine and executes the UNIX who command on each machine. The child creates a list of all the users on all the machines and returns this list to the parent agent for display to the user.

The who agent is included in the source code distribution.


* Source code


#!/usr/contrib/bin/agent

# This agent executes the "who" command on multiple machines.  It submits
# a SINGLE child agent.  The child jumps from machine to machine and
# executes the "who" command on each machine.  The child creates a list of
# all the users on all the machines and returns this list to the parent
# for display to the user.

  # Procedure WHO is the child agent that does the jumping.

proc who machines {

  global agent

  set list ""

     # jump from machine to machine

  foreach m $machines {

      # if we do not jump successfully append an error message
      # otherwise append the list of users 

    if {[catch "agent_jump $m"]} {
      append list "$m:\nunable to JUMP to this machine\n\n"
    } else {
      set users [exec who]
      append list "$agent(local-server):\n$users\n\n"
    }
  }

	# return the list of users

  return $list
}
   
  # list of machines -- make sure that you replace these with your machines

set machines "bald.cs.dartmouth.edu \
              cosmo.dartmouth.edu \
              lost-ark.dartmouth.edu \
              temple-doom.dartmouth.edu \
              unknown.cs.dartmouth.edu \
              moose.cs.dartmouth.edu \
              muir.cs.dartmouth.edu \
              tenaya.cs.dartmouth.edu \
              tioga.cs.dartmouth.edu \
              tuolomne.cs.dartmouth.edu"

  # register the agent

if {[catch {agent_begin}]} {
  return -code error "ERROR: unable to register on $agent(actual-server)"
}

  # catch any error

if {[catch {
 
    # submit the child agent that does the jumping 
    # Note that the result of the last command executed in the child agent is 
    # automatically sent to the parent as a message.  Here the last command
    # is the call to the WHO procedure so the result of the WHO procedure
    # is sent to the parent.  The result of the WHO procedure is the desired
    # list of users.

  agent_submit $agent(local-ip) -vars machines -procs who -script {who $machines}

    # wait for the list of users

  agent_receive code message -blocking

    # output the list of users

  puts "\nWHO'S WHO on our computers\n\n$message"

} error_message]} then {

    # make sure that we clean up on error

  agent_end

  return -code error -errorcode $errorCode -errorinfo $errorInfo $error_message

}

  # clean up

agent_end


* Sample output


WHO'S WHO on our computers

bald.cs.dartmouth.edu:
rgray    ttyp1    Aug  8 09:16 (:0.0)
rgray    ttyp2    Aug  8 09:19 (:0.0)

cosmo.dartmouth.edu:


lost-ark.dartmouth.edu:
gvc        ttyq2        Jul 25 15:40
moizumi    ttyq5        Aug  8 16:03

temple-doom.dartmouth.edu:


unknown.cs.dartmouth.edu:
unable to JUMP to this machine

moose.cs.dartmouth.edu:
berrin   ttyp0   Aug  8 14:36	(spectrum.xerox.c)
rgray    ttyp1   Aug  8 20:39	(bald.cs.dartmout)

muir.cs.dartmouth.edu:
kaun        ttyp1       Jul 18 09:51         
xsong       ttyp2       Aug 08 19:50         
xsong       :0          Aug 08 19:49         

tenaya.cs.dartmouth.edu:
rgray     

tioga.cs.dartmouth.edu:
olson       ttyp1       Aug 07 11:50         
mdengler    :0          Aug 06 20:07         

tuolomne.cs.dartmouth.edu:
rgray     


The D'Agents Project ended in approximately 2003. The software, and this web site, is no longer maintained. For questions please contact David Kotz.