55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/lab/driver/workstation_driver.rb', line 55
def run_command(command)
script_rand_name = rand(1000000)
if @os == "windows"
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.bat"
remote_tempfile_path = "C:\\\\lab_script_#{script_rand_name}.bat"
remote_output_file = "C:\\\\lab_command_output_#{script_rand_name}"
remote_run_command = remote_tempfile_path
File.open(local_tempfile_path, 'w') {|f| f.write(command) }
else
local_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
remote_tempfile_path = "/tmp/lab_script_#{script_rand_name}.sh"
remote_output_file = "/tmp/lab_command_output_#{script_rand_name}"
local_output_file = "/tmp/lab_command_output_#{script_rand_name}"
remote_run_command = remote_tempfile_path
File.open(local_tempfile_path, 'w') {|f| f.write("#!/bin/sh\n#{command}\n")}
end
if @tools
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
"copyFileFromHostToGuest \'#{@location}\' \'#{local_tempfile_path}\'" +
" \'#{remote_tempfile_path}\'"
system_command(vmrunstr)
if @os == "linux"
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
"runProgramInGuest \'#{@location}\' /bin/sh #{remote_tempfile_path} > #{remote_output_file}"
system_command(vmrunstr)
else
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
"runProgramInGuest \'#{@location}\' #{remote_tempfile_path} > #{remote_output_file}"
system_command(vmrunstr)
end
vmrunstr = "vmrun -T ws -gu #{@vm_user} -gp #{@vm_pass} " +
"deleteFileInGuest \'#{@location}\' \'#{remote_tempfile_path}\'"
system_command(vmrunstr)
local_delete_command = "rm #{local_tempfile_path}"
system_command(local_delete_command)
else
if @os == "linux"
scp_to(local_tempfile_path, remote_tempfile_path)
ssh_exec("/bin/sh #{remote_tempfile_path} > #{remote_output_file}")
scp_from(remote_output_file, local_output_file)
output_string = File.open(local_output_file,"r").read
ssh_exec("rm #{remote_output_file}")
ssh_exec("rm #{remote_tempfile_path}")
`rm #{local_output_file}`
else
raise "Hey, no tools, and windows? can't do nuttin for ya man."
end
end
output_string
end
|