ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.