Koozali.org: home of the SME Server

how to make SME email my gmail account with IP change

Offline KaiNeR

  • ****
  • 122
  • +0/-0
    • http://www.fire-blade.co.uk
how to make SME email my gmail account with IP change
« on: September 07, 2005, 01:27:01 AM »
My ISP is NTL and every now and then my ip is changed

How can i get my SME box to email my gmail account with the new IP address of eth1

any clues ? i have seen this done for dial up access i was just wondering if it was possible as i work away and it will be a nightmare if my ip gets updated.

Thanks in advance

Dave
KaiNeR  :pint: ......

Offline Curly

  • ****
  • 114
  • +0/-0
how to make SME email my gmail account with IP change
« Reply #1 on: September 08, 2005, 07:17:26 PM »
I think you've got two possibilities:
1) create a job in cron that checks every now and then
2) add something to one of the events that are triggered when your ip-address changes.

I think the second one is nicest, there should be a number of events that occur when the ip-address changes. Most of the events are in /etc/e-smith/events/actions.

I think that if you place your mail-script in the directory /etc/e-smith/events/ip-change, and make sure it gets executed last, you'll get what you want.

Name it something like S99_email_me, and it will get executed last. Dont forget to make it executable !
.......................................

Offline arne

  • *****
  • 1,116
  • +0/-4
how to make SME email my gmail account with IP change
« Reply #2 on: September 09, 2005, 12:27:57 AM »
One other way of doing this is to make a cronjob scheduled access to an other web server with a access log. Lets say every hour a web client on the server with dynamic ip makes an access to the web server with fixed ip. The maximum period of time the server can get lost will be 1 hour. I think normally a ip will not change very often when the server is "steady state" logged on.

I use such a mechanism to update dyndns.dk and normally my "dynamic ip" stays fixed for 2 or 3 months so there is rather little "down time" ("get lost time")
......

Offline arne

  • *****
  • 1,116
  • +0/-4
how to make SME email my gmail account with IP change
« Reply #3 on: September 09, 2005, 12:33:45 AM »
By the way .. If you use another router in front of the sme server so that the sme server has a local ip only, lets say 192.160.1.2 or 10.0.0.2, then there will be no need for server reconfiguration as the external ip adress changes. Have used this soulution with different Linux servers for years without a problem. The cron job that update a external dynamic dns address can on the other side run on the "internel" sme server with an intenal ip.
......

Offline KaiNeR

  • ****
  • 122
  • +0/-0
    • http://www.fire-blade.co.uk
how to make SME email my gmail account with IP change
« Reply #4 on: September 10, 2005, 09:42:16 AM »
Thanks for all the help, but how do i go about doing this ?

The SME server is the gateway so its at the front of the network with the expternal ip provided by my ISP and the external IP is on device ETH1

Thanks
Dave
KaiNeR  :pint: ......

Black

how to make SME email my gmail account with IP change
« Reply #5 on: September 11, 2005, 08:03:43 AM »
have you tried this?

* How to get SME's IP adress emailed, if it is not static?


Problem: The provider disconnects after 24 hours. You don't have a static IP, you won't or don't use dyndns and you want to recieve the actual IP of your server as soon as it's changed. All you need is an email-account somewhere. Works on all SME since 4.12.
Solution:


Edit

/etc/ppp/ip-up

and enter at before the exit 0
echo $4 | mail -s "New IP Myserver" your_desired@address.org

where "New IP Myserver" is a text at your choice and "your_desired@address.org" is your email adress.

(Mathias Bachmann)

Offline KaiNeR

  • ****
  • 122
  • +0/-0
    • http://www.fire-blade.co.uk
how to make SME email my gmail account with IP change
« Reply #6 on: September 11, 2005, 08:16:12 AM »
Quote from: "Black"
have you tried this?

* How to get SME's IP adress emailed, if it is not static?


Problem: The provider disconnects after 24 hours. You don't have a static IP, you won't or don't use dyndns and you want to recieve the actual IP of your server as soon as it's changed. All you need is an email-account somewhere. Works on all SME since 4.12.
Solution:


Edit

/etc/ppp/ip-up

and enter at before the exit 0
echo $4 | mail -s "New IP Myserver" your_desired@address.org

where "New IP Myserver" is a text at your choice and "your_desired@address.org" is your email adress.

(Mathias Bachmann)


Hi Black, thanks for the reply

i have tried doing that and it worked, the only problem is that it was emailing me the wrong ip, it was sending me the ip of eth0 instead of eth1. How can i change it to send the ip of eth1.

thanks
Dave
KaiNeR  :pint: ......

Robert

how to make SME email my gmail account with IP change
« Reply #7 on: September 11, 2005, 11:54:02 AM »
The only logical place for this kind of script is the ip-change event, like Curly said. That event gets triggered (at least in theory) whenever the external ip changes, regardless of whether your external interface is a ppp device or an eth device. Here's a link to a script that I used for some time:
http://forums.contribs.org/index.php?topic=7619.msg28032#msg28032

Offline KaiNeR

  • ****
  • 122
  • +0/-0
    • http://www.fire-blade.co.uk
how to make SME email my gmail account with IP change
« Reply #8 on: September 11, 2005, 12:28:36 PM »
thanks dudes, i've just created the script by following that thread, is there a way i can test it without rebooting the whole server ??

thanks for all the help
KaiNeR  :pint: ......

Robert

how to make SME email my gmail account with IP change
« Reply #9 on: September 11, 2005, 12:59:11 PM »
What I sometimes do is create a test event and then call it with the same arguments that the event you want to test is going to be called with.
So:
# mkdir /etc/e-smith/events/test-event
# cd /etc/e-smith/events/test-event
# ln -s ../actions/mail-external-ip S95mail-external-ip
# /sbin/e-smith/signal-event test-event 1.2.3.4

That should send an email to whatever you defined as $recipients in mail-external-ip saying the new external ip is 1.2.3.4.

If that doesn't work, you probably forgot to make the script executable. If it does work, you can then try to force a change of external ip by whatever method fits your ISP connection (unplugging and replugging cables often works). That should send a real external ip to $recipients.

Robert

how to make SME email my gmail account with IP change
« Reply #10 on: September 12, 2005, 08:32:17 PM »
Actually, I just checked and saw that there's a pretty glaring typo in the mail-external-ip script as reproduced in the earlier thread that I referred to. Trying to copy more carefully this time, here's the script I actually used:

#!/bin/sh

USER="noreply"
recipients="account1@domain1.tld account2@domain2.tld"
mail -s "$(hostname -f) now at $2" $recipients <<EOF
As of $(date) the external IP of $(hostname -f) is $2.
EOF

Offline KaiNeR

  • ****
  • 122
  • +0/-0
    • http://www.fire-blade.co.uk
how to make SME email my gmail account with IP change
« Reply #11 on: October 13, 2005, 06:21:44 PM »
Quote from: "Robert"
Actually, I just checked and saw that there's a pretty glaring typo in the mail-external-ip script as reproduced in the earlier thread that I referred to. Trying to copy more carefully this time, here's the script I actually used:

#!/bin/sh

USER="noreply"
recipients="account1@domain1.tld account2@domain2.tld"
mail -s "$(hostname -f) now at $2" $recipients <<EOF
As of $(date) the external IP of $(hostname -f) is $2.
EOF


Hi dude, sorry for being so dumb, but i followed your guide and now my server just keeps sending me emails with my local IP, which i really need it to send the external IP (ETH1)
can you please advise
thanks

sorry for being so thick :S
KaiNeR  :pint: ......

Robert

how to make SME email my gmail account with IP change
« Reply #12 on: October 13, 2005, 09:27:22 PM »
That's odd. Here's what should happen. A PPP or PPPoE or DHCP connection is established. The process that controls the connection (this can be pppd, pppoe, dhcpcd or whatever) will have a post-connection hook (/etc/ppp/ip-up.local, or /etc/dhcpc/dhcpcd-eth1.exe, or whatever) where you can run scripts/commands. SME Server will run "/sbin/e-smith/signal-event ip-change [new_ip]" in the post-connection hook. This means that all the parts in /etc/e-smith/events/ip-change will be run in order with a single argument, new_ip. This argument is available to the various parts of the event as $2 ($1 is the event itself). If you look at the first part of /etc/e-smith/events/ip-change, S15set-external-ip, it sets ExternalIP in /home/e-smith/configuration to the value of $2 (or $ARGV[1] in perl parlance). Later on the mail-external-ip part will send the value of $2 to the email address you specified. So, the ip address that's sent by mail-external-ip should be the same as the ExternalIP in /home/e-smith/configuration. Is this not true in your case?