From: sharmin malik Date: 2012-09-10T01:47:43+09:00 Subject: Re: Match an ARray Element by if Hi just wondering if you can help me my bellow logic, as its very related to this one I Need a logic for the bellow problem: I am running bellow script form a server, Hostname : Server-dk-2.domain.lan And We have 2 other servers Server-dh-2.domain Server-dm-2.domin Basically we have 3 server : Server-dk-2.domain.lan Server-dh-2.domain Server-dm-2.domin As you can see all same other then k,h,m So I want to run the script into other 2 servers . The logic is : If the script runs from server-dk-2.domain.lan , It should check server-dh-2.domain and server-dm-2.domain.lan I know how to connect to rest serve via ssh-net module But don’t understand how will I implement the logic of connecting the other 2 server Current code is where I have defined the host by hand but it has to be defined by its self So the logic is : if the current server is Server-dk-2.domain.lan , then those hostname1 and hostname2 will be Server-dh-2.domain and server-dm-2.domain.lan Or if current script running server is : Server-dh-2.domain the the hostnae1 and hostname 2 would be Server-dk-2.domain.lan , server-dm-2.domain.lan require 'net/ssh' def name_check(name) count =0 #Assuing I am running the script from Server-dk-2.domain.lan @hostname1 = " Server-dh-2-domain " @hostname2 = " server-dm-2.domain.lan " @username = "test" @password = "test" @cmd = "sudo ls /root/test/" begin ssh = Net::SSH.start(@hostname1, @username, :password => @password) res1 = ssh.exec!(@cmd) ssh.close sname = Array.new sname << res1 sname.each { |item| if (item =~ /#{name}/) count = count +1 } ssh = Net::SSH.start(@hostname2, @username, :password => @password) res2 = ssh.exec!(@cmd) ssh.close tname << res2 tname.each { |item| puts item if (item =~ /#{name}/) count = count +1 puts "its there" else "No tiem" end } if count >2 puts “We found two object” end rescue puts "Unable to connect to #{@hostname} using #{@username}/#{@password}" -- Posted via http://www.ruby-forum.com/.