#
# This is a script example, which shows how to run a shell command on a set of nodes
#
# The scenario of this experiment involves one set of nodes: 'mygroup'. We will execute
# the shell command 'ls -la' on all the nodes within that set. The output of this command
# will be sent back to (and displayed on) the console where this script is running.
#
# In this example we:
# 1) Define a set of nodes which contains 2 nodes: [1,1] and [1,2]
# 2) Execute the 'ls -la' shell command on these nodes 

# 1)
# Define a set of nodes which contains 2 nodes: [1,1] and [1,2]
defGroup('mygroup',[[1,1],[1,2]])  

# 2)
# When all the nodes are 'UP', execute the 'ls -la' shell command on them
whenAllUp() {
  
  # Print some info 
  puts "Execute commands /bin/ls on all nodes"
  
  # Use the 'exec' command on 'allNodes' to execute the shell command 'ls -la'
  # By default the output of the shell command will be sent back to and printed
  # on this console
  allGroups.exec("/bin/ls -la")

  wait 2 # wait 2 sec
  Experiment.done

  # OPTIONAL:
  # You can overwrite the default output processing of the command by defining a 
  # block when calling 'exec'
  #
  # For example, below we define a block which will print the outputs using our
  # own formatting
  #
  # allGroups.exec("/bin/ls -la") { |node, operation, eventName, message|
  #   puts " - We received an output from: #{node.name}"
  #   puts " - This output is: #{message}"
  # }
  #
  # In this other example below, we redirect the received outputs to a text file
  #
  # allGroups.exec("/bin/ls -la") { |node, operation, eventName, message|
  #   myFile = File.open("output.txt", "a+") do |f|
  #     f.puts " - We received an output from: #{node.name}"
  #     f.puts " - This output is: #{message}"
  #   end
  # }
}
