LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-27-2013, 08:01 AM   #1
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Rep: Reputation: Disabled
shell script


Hi,

i want to see which ip addresses are live and which ip addresses are dead so that i write a shell script as shown in below

#/bin/bash
ping=1
echo -e "\nenter ip range exampie is 10.10.3.:\c "
read number
while [ $ping -le 10 ]
do
ping -c 2 $number$ping
(( ping++ ))
done
but now i want save the file separately live and dead ip address
 
Old 04-27-2013, 11:42 AM   #2
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
sagar666,

You can check the manual page for ping on your distro, or just manually check the return code from the ping command. But on the distro I'm using, ping returns zero if successful, non-zero otherwise. So I would tend to do something like the following.


Code:
#!/bin/bash

echo -e "\nEnter base ip address, for example 10.10.3.:  \c "
read number

>  alive
>  dead

for ((  ping=1 ;  ping <= 10 ;  ping++  ))
    do

        ping -c 2 $number$ping

        if [[  $?  -eq  0  ]]
            then
                echo  $number$ping  >>  alive
            else
                echo  $number$ping  >>  dead
        fi

    done
So you'll get a list of the "live" IP addresses in the file named "alive" and those that are "dead" in the file named "dead".

I also might add something to check the format of the input value before using it.
 
Old 04-27-2013, 11:47 AM   #3
hyperdaz
Member
 
Registered: Sep 2004
Location: UK
Distribution: CentOS 5.5
Posts: 44

Rep: Reputation: 1
Job of nmap?

Code:
nmap -sP 10.10.3.0/25 > alive
will show all up hosts everything else is down

Last edited by hyperdaz; 04-27-2013 at 11:55 AM.
 
1 members found this post helpful.
Old 04-28-2013, 05:02 AM   #4
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Original Poster
Rep: Reputation: Disabled
Thanks rigor and hyperdaz

one more thing if host machine is in off it wont ping and it ip address goes to dead file. i want know only unassigned ip addresses even machines is in off ???
 
Old 04-28-2013, 06:20 AM   #5
hyperdaz
Member
 
Registered: Sep 2004
Location: UK
Distribution: CentOS 5.5
Posts: 44

Rep: Reputation: 1
Hi Sagar666,

I take it you have a full list of all hosts on the network, as any tool would not know if its "OFF" or "not assigned", ping or pretty much any networking tool is looking at what is turned ON.

As you are only scanning 10 IPs from your original script
Quote:
[ $ping -le 10 ]
or
Quote:
<= 10
this should be quite a fast check worth doing manually once or so even if this is a large network its probably worth the time to do a physical check make sure labelling is correct that you have all serial numbers and possibly warranty or support contracts or other licencees.

You can probably find most serial numbers of machines that are on with "dmesg"

If you are going to test the whole network something like 128 or 256 range then ping is going to take quite a long time not sure if that's an issue, nmap will take a much shorter time.

If you do have a work network or a large network then you might want to set up a monitoring tool this will check many different things for you non-stop i.e. something like Nagios Core http://www.nagios.org or (M)/Monit http://mmonit.com.

hdaz

Last edited by hyperdaz; 04-28-2013 at 06:29 AM.
 
Old 04-28-2013, 06:31 AM   #6
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Original Poster
Rep: Reputation: Disabled
Hi hdaz,

if i try to nmap -sP 10.10.3.0/25 > alive getting error nmap command not found
in redhat 6.1

sagar
 
Old 04-28-2013, 06:33 AM   #7
hyperdaz
Member
 
Registered: Sep 2004
Location: UK
Distribution: CentOS 5.5
Posts: 44

Rep: Reputation: 1
Just to confirm that is RHEL 6.1? or redhat 6.1 the latter was dated about 1996 and RHEL was a couple of years ago

to be sure run:
Code:
 cat /etc/redhat-release
I'll take it it's RHEL 6.1 is there any reason why your still on 6.1? 6.4 is the latest version there might be logical reasons for not upgrading if this is a locked down network but normally it is highly recommended to update to the latest to get full security fixes/patches etc.

to install nmap on RHEL
Code:
 up2date install nmap
or if yum is installed i.e. CentOS rather than RHEL

Code:
 yum install nmap
I will also add that if this is a corporate network then one might be restricted to install applications such as nmap.

Nmap is a very powerful tool that can gather a lot of information with different optoins etc, then if you are not the Admin of the network/servers/VMs/desktops then you might want to ask for permission first.

Hdaz

Last edited by hyperdaz; 04-28-2013 at 06:44 AM.
 
Old 04-28-2013, 07:35 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,344

Rep: Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746Reputation: 2746
Quote:
to install nmap on RHEL....
Actually, Centos is a rebuild of RHEL, and RHEL switched to yum as of 5.0.
Later versions of v4 (4.8, 4.9 ??) also had the option to install and use yum instead of up2date.
 
Old 04-28-2013, 07:49 AM   #9
sagar666
Member
 
Registered: Feb 2013
Posts: 212

Original Poster
Rep: Reputation: Disabled
I installed nmap .Now it is working fine and also very powerful tool.we can verify all up ips with a seconds
Thank u very much
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 script for run an shell script on server using ssh bloodstreetboy Linux - Server 5 01-12-2013 03:23 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:49 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