LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-02-2009, 12:00 AM   #1
himitsu
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Rep: Reputation: 0
Shell scripting question


HI,

I am trying to get a ping request on all live host.

#!/bin/bash
# Ping all IP numbers in 192.168.9.0/24.*
# Record the host names of those that respond
rm live-hosts
for(( n=0 ; $n < 255 ; n=$n+1 ))

do

ip=192.168.9.0/24.$n
if true #ping -c 1 -w 1 $ip
then
host=‘host $ip‘
echo $host >> live-hosts.txt

fi
done

When I run this script I get line 12 no file or directory. What am I doing wrong here. Any help would be great thanks
 
Old 09-02-2009, 12:29 AM   #2
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
use the ` instead of the '
 
Old 09-02-2009, 01:53 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
On a second note:

192.168.9.0/24.1 is not a valid IP address. Get rid of
the range if you're pinging individual hosts.

Code:
ip=192.168.9.$n

Cheers,
Tink
 
Old 09-02-2009, 01:53 AM   #4
SwaJime
LQ Newbie
 
Registered: May 2009
Distribution: Ubuntu, CentOS, Redhat, Maemo
Posts: 10

Rep: Reputation: 1
Question

Quote:
Originally Posted by himitsu View Post
HI,

I am trying to get a ping request on all live host.

#!/bin/bash
# Ping all IP numbers in 192.168.9.0/24.*
...
Why don't you use #ping -b 192.168.9.0; ?
The command "ping 192.168.9.0/24.1" does not work on my system. I've never seen that syntax before.
 
Old 09-02-2009, 02:25 AM   #5
JulianTosh
Member
 
Registered: Sep 2007
Location: Las Vegas, NV
Distribution: Fedora / CentOS
Posts: 674
Blog Entries: 3

Rep: Reputation: 90
Quote:
Originally Posted by Admiral Beotch View Post
use the ` instead of the '
lol. woops. sleep. need sleep. sorry.
 
Old 09-02-2009, 06:08 PM   #6
himitsu
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Another question

Hi,
Thanks for the help

When I run the shell I get the following
ping: unknown host 192.168.8.1

Any ideals

Thanks




Quote:
Originally Posted by Tinkster View Post
On a second note:

192.168.9.0/24.1 is not a valid IP address. Get rid of
the range if you're pinging individual hosts.

Code:
ip=192.168.9.$n

Cheers,
Tink
 
Old 09-02-2009, 06:26 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
A wild guess. When I copied your script from the browser there
was a load of "weird" characters where your ' were ...

Is it possible that you have some unicode whitespace tacked
on there somewhere?


Cheers,
Tink
 
Old 09-02-2009, 08:28 PM   #8
himitsu
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Another ideal

HI,

I do thank you for the help

This seems to work.

#!/bin/bash
for ((n=0 ; n < 255 ; n+=1))
do

ip=192.168.9.$n
if ping -c 1 -w 1 $ip

then
host=&ip
echo $host >> live-host.txt
fi
done

Is this one way to determine if a host is up by pinging?



Quote:
Originally Posted by Tinkster View Post
A wild guess. When I copied your script from the browser there
was a load of "weird" characters where your ' were ...

Is it possible that you have some unicode whitespace tacked
on there somewhere?


Cheers,
Tink
 
Old 09-02-2009, 08:46 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
It certainly is ... it might be quicker/easier to use nmap, though

Code:
nmap -sP 192.168.9.0/24
 
Old 09-02-2009, 08:59 PM   #10
himitsu
LQ Newbie
 
Registered: Aug 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the help

Thanks for the help


I like to hard route before the easy one.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting Question Echo Kilo Linux - Newbie 5 05-11-2008 04:08 AM
shell scripting question angelofhope Linux - Software 5 08-22-2007 04:18 PM
shell scripting question Komelore Linux - Software 3 03-12-2007 04:21 AM
a shell-scripting question: mrchaos Slackware 3 09-22-2005 11:00 AM
Shell scripting question. dragin33 Linux - General 2 08-11-2004 05:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration