LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   scripting (https://www.linuxquestions.org/questions/linux-software-2/scripting-631813/)

rehan999 03-31-2008 12:47 AM

scripting
 
Good Morning

I have 20 Linux machnies with static IP's and all this machnies are installed with redhat enterprise linux 4.3 .

I want to write a script to check how many machnies are up and how many machnies are down.

Please help me out its urgent...

Thanks and Regards
Rehan

chrism01 03-31-2008 12:53 AM

Well a quick 'n dirty way is:

Code:

# Assume list of ip addrs in a file, 1 ip per line
for ip in `cat ips.dat`
do
    ping -c1 $ip >/dev/null/ 2>&1
    if [[ $? -eq 0 ]]
    then
        echo "$ip is up"
    else
        echo "$ip is down"
    fi
done


konsolebox 04-04-2008 02:11 AM

try to use nmap. it's a lot quicker.
Code:

nmap -n -sP -iL ips.dat
nmap -n -sP 10.0.0.1 192.168.0.1 ...


rehan999 04-08-2008 05:00 AM

Thanks you very much for the replies.

# Assume list of ip addrs in a file, 1 ip per line
for ip in `cat ips.dat`
do
ping -c1 $ip >/dev/null/ 2>&1
if [[ $? -eq 0 ]]
then
echo "$ip is up"
else
echo "$ip is down"
fi
done


The code really helped me.i have just made modifications according to my requirment

Thanks u very much


All times are GMT -5. The time now is 07:37 AM.