_Agent Tcl_
by Robert S. Gray

Listing One
  # procedure WHO is the child agent that does the jumping 
proc who machines { 
  global agent 
  set list "" 
    # jump from machine to machine and execute Unix who command on each machine
  foreach m $machines { 
    if {catch "agent_jump" $m"} { 
      append list "$m:\n unable to JUMP to this machine" 
    else { 
      set users [exec who] 
      append list "$agent(local-server):\n$users\n\n" 
    } 
  } 
  agent_send $agent(root) $list 
  exit
} 
set machines "bald cosmo lost-ark temple-doom moose muir tenaya tioga tuolomne"
  # get a name from the server 
agent_begin 
  # submit the child agent that jumps 
agent_submit $agent(local-ip) -vars machines -procs who -script {who $machines}
  # wait for and output the list of users 
agent_receive code string -blocking 
puts $string 
  # agent is done 
agent_end 

Listing Two
bald.cs.dartmouth.edu: 
rgray    ttyp2    Sep  5 21:24 (:0.0) 
rgray    tty6     Sep  7 07:14  

cosmo.dartmouth.edu: 
gvc         pts/0       Aug 23 10:11 
 ... 

Listing Three
set email_agent "bald rgray_email"      # machine and name of email agent 
set machines "bald moose" 
set directory "~rgray" 
  # get a name from the server 
agent_begin  
  # submit the "file" agents that watch for changes in file size 
for each m $machines { 
  agent_submit $m -vars directory -proc file_watch {file_watch $directory} 
} 
  # wait for one of the "file" agents to send a message saying that the 
  # status of a file has changed; then send an alert message to the user 
  # by asking the user's email agent to send a message to its owner 
while {1} { 
} 
  agent_receive code string -blocking 
  set alert [construct_alert $string] 
  agent_send $email_agent {SEND OWNER $alert} 
}



