Tutorial/HowToCommand: tut_cmd_1.rb

File tut_cmd_1.rb, 1.7 KB (added by thierry, 16 years ago)
Line 
1#
2# This is a script example, which shows how to run a shell command on a set of nodes
3#
4# The scenario of this experiment involves one set of nodes: 'mygroup'. We will execute
5# the shell command 'ls -la' on all the nodes within that set. The output of this command
6# will be sent back to (and displayed on) the console where this script is running.
7#
8# In this example we:
9# 1) Define a set of nodes which contains 2 nodes: [1,1] and [1,2]
10# 2) Execute the 'ls -la' shell command on these nodes
11
12# 1)
13# Define a set of nodes which contains 2 nodes: [1,1] and [1,2]
14defGroup('mygroup',[[1,1],[1,2]])
15
16# 2)
17# When all the nodes are 'UP', execute the 'ls -la' shell command on them
18whenAllUp() {
19
20 # Print some info
21 puts "Execute commands /bin/ls on all nodes"
22
23 # Use the 'exec' command on 'allNodes' to execute the shell command 'ls -la'
24 # By default the output of the shell command will be sent back to and printed
25 # on this console
26 allGroups.exec("/bin/ls -la")
27
28 wait 2 # wait 2 sec
29 Experiment.done
30
31 # OPTIONAL:
32 # You can overwrite the default output processing of the command by defining a
33 # block when calling 'exec'
34 #
35 # For example, below we define a block which will print the outputs using our
36 # own formatting
37 #
38 # allGroups.exec("/bin/ls -la") { |node, operation, eventName, message|
39 # puts " - We received an output from: #{node.name}"
40 # puts " - This output is: #{message}"
41 # }
42 #
43 # In this other example below, we redirect the received outputs to a text file
44 #
45 # allGroups.exec("/bin/ls -la") { |node, operation, eventName, message|
46 # myFile = File.open("output.txt", "a+") do |f|
47 # f.puts " - We received an output from: #{node.name}"
48 # f.puts " - This output is: #{message}"
49 # end
50 # }
51}