LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-13-2011, 10:24 PM   #1
wolverene13
Member
 
Registered: May 2010
Location: Matiland, FL
Distribution: Debian Squeeze
Posts: 57

Rep: Reputation: 0
Need help with while loop/ARP script in bash


Hi guys,

I am trying to write a script wherein bash reads from a list of IP's, pings them to generate an ARP entry for any nodes with those IP addresses, and then finds a particular entry based on MAC address. Why, you ask? Well, I have a Cisco WAP that pulls its address via DHCP and I'd like to be able to update its DNS entry in BIND dynamically, but it's not capable of that as far as I know. So, I figure I can obtain its IP via ARP (by using the script) for use in another script that will dynamically update my DNS files. Here's what I have so far, but it doesn't seem to work right. "localips.txt" is the list of possible DHCP addresses, "arpentries.txt" is going to be the file that is generated that contains the ARP entries that are generated, and "00:0b:5f:5f:03:bb" is the MAC of the WAP. The output will go to "tsunamisip.txt", which should ultimately be the IP of the WAP. Any ideas? Thanks in advance!

Code:
#!/bin/bash

cat localips.txt | while read host
do ping -c 1 $host && sudo arp $host | tee arpentries.txt
cat arpentries.txt | grep 00:0b:5f:5f:03:bb | cut -c 1-11 | tee tsunamisip.txt
done
 
Old 06-13-2011, 11:32 PM   #2
binary_pearl
Member
 
Registered: Jul 2007
Location: Chicago Illinois
Distribution: SLES 10 SP2/SP3, SLES 11 SP1, OpenSUSE, Sabayon, Gentoo, Fedora 14, RHEL 3/4/5/6
Posts: 98
Blog Entries: 3

Rep: Reputation: 23
My knowledge of IOS is very limited, but do you have the capability of using perl or python? The complexity of what you are trying to do scripting-wise might be easier in one of those languages, assuming you have the time to learn one of them if your not already familiar.

Another thought, check out:
http://dag.wieers.com/howto/bits/bind-ddns.php

I believe `nsupdate` is used to dynamically update BIND. If that works, you might be able to avoid having to script your own solution.

--Shaun
 
Old 06-14-2011, 12:11 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
ummm ... I do not use arp but from examples I have found, it seems to say the ip address would be in the second column and not the first, as indicated by your cut?? I will use this format for my example, but you can easily change $2 to $1 in the awk:
Code:
while read -r host
do
    ping -c1 -q $host &>/dev/null && sudo arp $host | awk '{print $2}' >> tsunamisip.txt
done<localips.txt
 
  


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
how to loop over text file lines within bash script for loop? johnpaulodonnell Linux - Newbie 9 07-28-2015 03:49 PM
Bash script Question while loop glennph93 Programming 6 05-25-2007 03:27 PM
bash script loop bong.mau Programming 6 09-14-2005 07:38 PM
bash script (arp) xviddivxoggmp3 Programming 8 04-20-2005 05:51 PM
bash script for loop drisay Programming 5 12-25-2004 12:32 AM

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

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