Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything 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.
When dhcpd ( running on Debian Etch 4 ) leases an IP address I want my script to be notified. The script will likely be a bash script. I should receive the MAC address, IP address and the lease time. I should also receive a notification if the lease is released by the customer.
I'll need root privileges for the commands executed. ( Or I could program sudo to allow me to execute the commands needed ).
You could set a tail on the dhcpd log and pipe it into your processing.
I am running F9 so your setup is quite probably somewhat different. But the following may be helpful.
I have set my dhcpd to log into its own file but that is not really necessary as by default it will log into /var/log/messages and can be sorted out like this:
sudo tail --follow=name /var/log/messages | grep dhcpd | your-processing-script
My set up put it in its own file, /var/log/dhcpdlog by including the following:
in my /etc/dhcpd.conf
log-facility local1; # per /etc/rsyslog.conf setting
in my /etc/rsyslog.conf
# log dhcpd per /etc/dhcpd.conf
local1.* /var/log/dhcpdlog
I do have the logs rotated by /usr/sbin/logrotate (see man logrotate) by adding the following to /etc/logrotate.d/syslog:
Your script will have to look for the offer and the ack packets in this log. Here is a request, acknowledge, and inform secguence from the log:
Nov 27 07:11:51 maplepark dhcpd: DHCPREQUEST for 192.168.102.95 (192.168.102.9) from 00:c0:a8:da:94:35 (drf-PC) via eth0
Nov 27 07:11:51 maplepark dhcpd: DHCPACK on 192.168.102.95 to 00:c0:a8:da:94:35 (drf-PC) via eth0
Nov 27 07:16:22 maplepark dhcpd: DHCPINFORM from 192.168.102.114 via eth0
Nov 27 07:16:22 maplepark dhcpd: DHCPACK to 192.168.102.114 (00:00:39:1b:43:0e) via eth0
I do run dynamic updates to my bind and they show up as:
when adding:
Nov 27 09:47:30 maplepark dhcpd: DHCPDISCOVER from 00:c0:a8:da:94:35 via eth0
Nov 27 09:47:31 maplepark dhcpd: DHCPOFFER on 192.168.102.95 to 00:c0:a8:da:94:35 (drf-PC) via eth0
Nov 27 09:47:31 maplepark dhcpd: Added new forward map from drf-PC.maplepark.com to 192.168.102.95
Nov 27 09:47:31 maplepark dhcpd: added reverse map from 95.102.168.192.in-addr.arpa. to drf-PC.maplepark.com
Nov 27 09:47:31 maplepark dhcpd: Wrote 0 deleted host decls to leases file.
Nov 27 09:47:31 maplepark dhcpd: Wrote 0 new dynamic host decls to leases file.
when deleting:
Nov 27 08:11:51 maplepark dhcpd: if drf-PC.maplepark.com IN TXT "31467d5c297125ea22734a4e36c193b583" rrset exists and drf-PC.maplepark.com IN A 192.168.102.95 rrset exists delete drf-PC.maplepark.com IN A 192.168.102.95: success.
Nov 27 08:11:51 maplepark dhcpd: if drf-PC.maplepark.com IN A rrset doesn't exist delete drf-PC.maplepark.com IN TXT "31467d5c297125ea22734a4e36c193b583": success.
Nov 27 08:11:51 maplepark dhcpd: removed reverse map on 95.102.168.192.in-addr.arpa.
Nov 27 08:45:40 maplepark dhcpd: Wrote 0 deleted host decls to leases file.
Nov 27 08:45:40 maplepark dhcpd: Wrote 0 new dynamic host decls to leases file.
The interesting thing here is that, although the lease was deleted in bind at 8:11:51, the lease file was not written to until 8:45:40. I suspect that using the lease file as gospel truths may be an error as it is primarily to store information for dhcpd's use between requests and shutdowns, not as an up-to-date snapshot available for other processes to use. But your needs will dictate if you can use it. Other dhcpd daemons, fallover particularily, could also change the actual picture from what you expect.
I'm looking for exactly the same thing, I got the tail /var/log/syslog | grep "dhcpd: DHCPACK"
But how do i get just the ip address from the whole line:
Dec 14 12:23:09 ubuntu dhcpd: DHCPACK on 192.168.0.30 to bla bla
Skiltron, just pipe the output of your tail /var/log/syslog | grep "dhcpd: DHCPACK" into cut
cut picks out things by their field position and is described in man cut
For your request to see the IP, it could simply look like this:
tail /var/log/syslog | grep "dhcpd: DHCPACK" | cut -d " " -f 8 | your-processing-script
You could use awk which is more powerful but requires some educational effort. Many books are available.
A simple awk:
/usr/bin/tail --follow=name /var/log/syslog | awk -f some_plugin |bash where your plug in can be quite versitle
an example might be like the routine I use to catch rogue ssh logins on my machine as detailed at: http://maplepark.com/~drf/consults/Killit_Plan.html
But the quickest might be the "cut" example as above. You might want to add the --follow=name option to the tail for a continuous daemon.
I got the tail, grep and cut statements and put it in a variable..
Echo the variable and there it is!
If I add the --follow that doesn't work anymore
I'd like it to run an application and give the app the ip-address
As you might have noticed I'm new to shell scripts :P
I got the tail, grep and cut statements and put it in a variable..
Echo the variable and there it is!
If I add the --follow that doesn't work anymore
I'd like it to run an application and give the app the ip-address
As you might have noticed I'm new to shell scripts :P
No, I never made the script. I had other things come up. I'll come back to this eventually.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.