Ip up/down testing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ip up/down testing
# 1  
Old 06-23-2013
Ip up/down testing

Code:
#!/bin/bash
 ip=$1 
 if [ -z "$ip" ]; then 
  echo "U must enter ip as argument: $0 [ip]" 
  exit 1
 fi
 testip=`echo $ip |grep -E "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"`
 if [ -z "$testip" ]; then   
echo "Wrong ip adress" 
  exit 2
 fi
 ping -c 2 $ip 2>&1 >/dev/null
 if [ $? -eq 0 ]; then 
  echo "$ip is UP"
 else
 echo "$ip is DOWN"
 fi 
 exit 0

This is the script thet checks is the ip is up or down..
for exmp ./iptest.sh xxxx.xxxx.xxxx.xxxx

But i dont know how to make same script that reads ip adresses from a file.
for exmp if i have a file ip.txt,and there are like 5 adresses written inside,what do i need to add so my script reads the file and writes me down are the ips UP or down?
Thnx a lot

Last edited by DukeNuke2; 06-23-2013 at 05:45 PM..
# 2  
Old 06-23-2013
Try replacing ip=$1 with while read ip; do and exit 0 with done < ipfile; exit 0. This should loop through your ipfile and exit when done.
This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-23-2013
Works,thanx a lot!
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

testing

first time use (0 Replies)
Discussion started by: lcharles
0 Replies

2. UNIX for Advanced & Expert Users

testing

what is the difference between white box and black box testing? (1 Reply)
Discussion started by: areef4u
1 Replies

3. UNIX for Advanced & Expert Users

testing

what does one mean in the context of testing... UNIT TESTING & INITIAL LEVEL OF MENU TESTING (2 Replies)
Discussion started by: areef4u
2 Replies
Login or Register to Ask a Question