7 Replies - 6887 Views - Last Post: 31 July 2017 - 01:33 PM Rate Topic: -----

#1 Techsouls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 17

script for pinging multiple IP address and get the status

Posted 29 July 2017 - 10:44 PM

I'm looking to write a Ruby script to ping some of my Linux Servers IP addresses and display the status whether they are up or down. I am looking to achieve this on a ubuntu linux console. The script should pick the urls/fqdns/Ip address from the text file and should ping them in Linux console in order to get the results. Thank You very much in advance.
I am new to Ruby and would very much appreciate all the help I can get.

This post has been edited by andrewsw: 29 July 2017 - 11:15 PM
Reason for edit:: removed "Ruby" from topic title

Is This A Good Question/Topic? 0
  • +

Replies To: script for pinging multiple IP address and get the status

#2 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 595
  • View blog
  • Posts: 2,493
  • Joined: 13-June 14

Re: script for pinging multiple IP address and get the status

Posted 29 July 2017 - 11:00 PM

Ok. What have you attempted so far?
Was This Post Helpful? 0
  • +
  • -

#3 Techsouls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 17

Re: script for pinging multiple IP address and get the status

Posted 29 July 2017 - 11:07 PM

[quote name='ndc85430' date='29 July 2017 - 11:00 PM' timestamp='1501394415' post='2331356']
Ok. What have you attempted so far?
[I'm just trying with 'net/ping' function but it wouldn't worked out.
Thanks]

#!/usr/bin/env ruby

require 'net/ping'

def up?(host)
check = Net::Ping::External.new(host)
check.ping?
end

chost = '10.0.0.1'
puts up?(chost) # prints "true" if ping replies
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 595
  • View blog
  • Posts: 2,493
  • Joined: 13-June 14

Re: script for pinging multiple IP address and get the status

Posted 29 July 2017 - 11:45 PM

Please use code tags around your code, as you're asked in the box where you type your post.

What specifically doesn't work?
Was This Post Helpful? 0
  • +
  • -

#5 Techsouls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-July 17

Re: script for pinging multiple IP address and get the status

Posted 30 July 2017 - 12:41 PM

View Postndc85430, on 29 July 2017 - 11:45 PM, said:

Please use code tags around your code, as you're asked in the box where you type your post.

What specifically doesn't work?

The code which i mentioned was executed in one of the ruby platform console in order to test that but unfortunately i am getting this below error.

[/temp/file.rb:2: unknown regexp option - b
/temp/file.rb:2: warning: regex literal in condition
/temp/file.rb:2: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '(']


Please help me out since i am very new to ruby i couln't able to figure it out.
Thanks.
Was This Post Helpful? 0
  • +
  • -

#6 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 595
  • View blog
  • Posts: 2,493
  • Joined: 13-June 14

Re: script for pinging multiple IP address and get the status

Posted 30 July 2017 - 10:31 PM

Are you sure you're running the right script? The first of those errors seem to be about regular expressions and you aren't using any in the code you've posted.

I also know very little about Ruby, to be honest.
Was This Post Helpful? 1
  • +
  • -

#7 NeoTifa  Icon User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4083
  • View blog
  • Posts: 18,159
  • Joined: 24-September 08

Re: script for pinging multiple IP address and get the status

Posted 31 July 2017 - 12:50 PM

Try replacing chost to be '10\.0\.0\.1'
Was This Post Helpful? 0
  • +
  • -

#8 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2512
  • View blog
  • Posts: 3,992
  • Joined: 21-June 11

Re: script for pinging multiple IP address and get the status

Posted 31 July 2017 - 01:33 PM

Your code works fine for me. But if I remove the # at the beginning, I get the exact same error message as you (except I get it on line 1, not 2). So my guess is that ndc is right and you're running different code than what you posted. That or you have some invisible Unicode hijinks going on in your file that somehow eat the #.

View PostNeoTifa, on 31 July 2017 - 09:50 PM, said:

Try replacing chost to be '10\.0\.0\.1'


This will just produce a host name with backslashes in it, which ping won't know what to do with (or rather it will think they're part of the host name).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1