Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grep in Script

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
Platform = Solaris 8

I'm trying to create a IP/Mac discovery script

a=1
rm /tmp/ping.look
while [ "$a" -le 254 ]
do
ping 192.168.24.$a 1 >> /tmp/ping.look
arp -a| /usr/xpg4/bin/egrep -x 192.168.24.$a >> /tmp/ping.look
a=`expr $a + 1`
echo $a
done

All works fine apart from the Mac address bit where I'm getting the following problem

no answer from 192.168.24.1
eri0 192.168.24.15 255.255.255.255 00:01:02:8d:9e:f3
eri0 192.168.24.1 255.255.255.255 U
no answer from 192.168.24.2
eri0 192.168.24.253 255.255.255.255 00:00:0c:07:ac:18
eri0 192.168.24.232 255.255.255.255 00:01:e6:14:6a:c0
eri0 192.168.24.29 255.255.255.255 00:50:8b:60:54:b4
eri0 192.168.24.2 255.255.255.255 U
no answer from 192.168.24.3
eri0 192.168.24.33 255.255.255.255 00:50:8b:dc:d9:bf
eri0 192.168.24.37 255.255.255.255 00:80:5f:d7:a3:e4
eri0 192.168.24.3 255.255.255.255 U
no answer from 192.168.24.4
eri0 192.168.24.45 255.255.255.255 00:06:29:55:8a:04
eri0 192.168.24.46 255.255.255.255 00:0c:ce:77:29:ff
eri0 192.168.24.4 255.255.255.255 U
no answer from 192.168.24.5
eri0 192.168.24.5 255.255.255.255 U
no answer from 192.168.24.6
eri0 192.168.24.65 255.255.255.255 00:50:8b:69:8e:65
eri0 192.168.24.6 255.255.255.255 U

How do I only list the Mac address that belongs to the IP?

-
| Mike Nixon
| Unix Admin
-------------
 
Replace this:
arp -a| /usr/xpg4/bin/egrep -x 192.168.24.$a >> /tmp/ping.look
By this:
arp -a|grep "192.168.24.$a " >> /tmp/ping.look

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I need to match the pattern exactly so using

arp -a|grep "192.168.24.$a " >> /tmp/ping.look

would provide the same result as I'm getting now.

-
| Mike Nixon
| Unix Admin
-------------
 
Even with the space between $a and " ?
arp -a|grep "192.168.24.$a{highlight] [/highlight]" >> /tmp/ping.look
If yes, you can try this:
arp -a|grep "192.168.24.$a[ ]" >> /tmp/ping.look

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Cheers that works only I have to add the following

arp -a| grep "192.168.24.$a[ ]"|grep -v U >> /tmp/ping.look

as each line that isn't pingable produces

no answer from 192.168.24.5
eri0 192.168.24.5 255.255.255.255 U



-
| Mike Nixon
| Unix Admin
-------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top