Koozali.org: home of the SME Server

ip change notification script help

Bart Wittkampf

Re: ip change notification script help
« Reply #15 on: September 28, 2003, 03:21:24 PM »
Oops sorry about the ‘shortcut’ part!  I will call them ‘links’ from now on :-)

# sh mail-external-ip one two

Returned a mail with: “your IP address is now two”. So that means that $2 needs to be my external ip. Let me take a look at your script:

#!/bin/sh
recipients="bart@alternatemailaddress.nl"
IP=/sbin/e-smith/db configuration get ExternalIP
mail -s "hostname -f now at $IP" $recipients <As of date the external IP of hostname -f is $IP.
EOF

I tested:

# sbin/e-smith/db configuration get ExternalIP

Which resulted in my IP address. So that is a good thing. I PICO’ed the script, and saved it to mail-external-ip.

Now let’s test the script:

# sh mail-external-ip

Yes, I received a mail with my external IP address. So it seems the script works. Now it is waiting till my external IP address changes, so I can see it in action. Is there a way to force an IP change (with a release command?)? And one more question: does this script still work after rebooting the server?

Have a nice day!

Bart

Bart Wittkampf

Re: ip change notification script help
« Reply #16 on: September 28, 2003, 05:07:43 PM »
I checked the script with
# /sbin/dhcpcd eth1 -k
# /sbin/dhcpcd eth1 -n

(kill & renew of lease)

It worked. There is one strange thing however. I checked it twice and the first time I received a mail from root@myadress, and the second time from anonymous@myadress. Pretty strange...... anyone have an explanation?

Bart

Robert

Re: ip change notification script help
« Reply #17 on: September 29, 2003, 12:41:08 AM »
Maybe I can help, since I wrote that mail-external-ip scriptlet. Of course the scriptlet won't know what $2 is outside the proper context. That's why you put it in the ip-change event. signal-event calls ip-change (1st argument) with the new external ip as second argument. Look at set-external-ip. I think it's overkill to first store the ip in the configuration dbfile and then fire up a perl script to get it out of the dbfile again. That's why I used the positional parameter. HTH

Bart Wittkampf

Re: ip change notification script help
« Reply #18 on: September 29, 2003, 01:05:06 AM »
Haha! I checked it, and the original script works exactly as it should work:

#!/bin/sh

recipients="address1@domain1.tld address2@domain2.tld"
mail -s "hostname -f now at $2" $recipients <As of date the external IP of hostname -f is $2.
EOF

I feel kinda stupid now, but at least a learned a few things about SME!

Thanks for the update!

Bart

Jim Danvers

Re: ip change notification script help
« Reply #19 on: September 29, 2003, 06:39:59 AM »
Hey Bart, and everyone else...

This really turned out to be quite the little thread, eh?  Bart - I'd say that you learned a little more than just something relevant to SME - you (we) all prolly picked up on a thing or two on linux and some basic bash/shell scripting in general.  Good stuff indeed.  I'm planning on playing around with the results of this thread myself (the script that you are now using) on another machine that I'm thinking about cobbing together.  I don't really have a need for it on the sme box that I use @present for my own uses as I use a dyndns service for my little domain name.  The other box that I'm thinking about running though won't have a domain name attached to it - this solution would be perfect.  ;)

-=- jd -=-