@TK_STARTUP@

# who.jump.tk
#
# This agent jumps from machine to machine and executes the Unix "who" command
# on each machine.  Then it returns to its home machine and displays the user
# list in a window.

  # Procedure WHO executes the who command on each machine.

proc who machines {

  global agent 

     # remember the home machine

  set home $agent(local-ip)

     # jump from machine to machine and execute the "who" command on each

  set list ""

  foreach m $machines {

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

    if {[catch "agent_jump $m" result]} {

      append list "$m:\nunable to JUMP to this machine ($result)\n\n"

    } else {

	# as with the other "who" agents, note that we must redirect standard
	# input

      catch {
	exec who << {}
      } users

      append list "$agent(local-server):\n$users\n\n"
    }
  }

    # return to the home machine

  agent_jump $home

    # make the main window and show the results

  main create -name "WHO'S WHERE?" -display $agent(actual-server):0

    # make the two frames

  frame .top -relief raised -bd 1
  frame .bot -relief raised -bd 1
  pack .bot -side bottom -fill both
  pack .top -side bottom -fill both -expand 1

    # make a text box that will hold the results

  text .text -relief raised -bd 2 -yscrollcommand ".scroll set"
  scrollbar .scroll -command ".text yview"
  pack .scroll -in .top -side right -fill y 
  pack .text -in .top -side left -fill both -expand 1 

    # make the "DONE" button

  button .done -text OK -command "set done 1"
  pack .done -in .bot -side left -expand 1 -padx 3m -pady 2m

    # fill in the text area

  .text delete 1.0 end
  .text insert end $list

    # wait for the user to finish looking at the results

  tkwait variable done
}
 
  # turn on agent verification

set code [
    catch {
       security signatures on
    } result
]

if {$code} {
    puts "Unable to turn on digital signatures:"
    puts ""
    puts $result
    puts ""
    puts "Proceeding anyways ..."
    puts ""
}

  # get the list of machines

puts "Please enter a list of machines:"
gets stdin machines

  # register the agent

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

  # submit the agent that jumps from machine to machine

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

  # wait for that agent to finish

set source [agent_receive code string -blocking]

if {$code == "0"} {
    puts "Done!"
} else {
    puts "Error in child (while on machine [lindex $source 0]):"
    puts [lindex $string 2]
}

  # we're done

agent_end
exit
