tags:

views:

85

answers:

2

If i have a # {} , like #{results}, in the snippet below:

results = Array.new                                   f = open("/Users/kahmed/messages", "r")                                   f.each_line do |line|                                        results << "#{$.} #{line}" if line =~ /NFE/                                       put #{results}                                   end

How can i use it in the following ssh.exec command

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh|                                   ssh.exec(#{results})

A: 

Something like:

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh| 
  results.each{|line| ssh.exec( line)}
end
steenslag
A: 

Hi Steenslang, thanks for your suggestion, but perhaps i was not entirely clear:

here is the complete snippet:

results = Array.new f = open("messages", "r") f.each_line do |line| results << "#{$.} #{line}" if line =~ /error/ end lastline = results.pop() if ! results.empty?

                          # run shell command to email

Net::SSH.start( HOST, USER, :password => PASS ) do|ssh| ssh.exec(' hostname | /usr/local/bin/smtpclient -s lastline -S smtp.mail.com -v [email protected] > /my.out 2>&1') do|ch, stream, data| end

now..... inside the ssh.exec() block i wand to use the "result" which is the last line , but ssh.exec(result) is not possible since ssh.exec is outside of the program flow and executing an external command. I hope now it makes more sense , sorry for not clearly explaining the first time.

kamal
You should edit things into your question, rather than posting an answer.
Xiong Chiamiov