On debian 8.9

I want to check my ip address and send email every hour.

what I want to do is

1.Check my server ip address -> curl globalip.me2.Send ip address by email.

A. I know how to send mail in command line.B. I know how to setup crond.

However A requires manual response, so I don't know how to use A in B setting.

Is there any good way ??

  • fyi; if you're trying to keep track of your server's public address, you want dynamically updated dns, not sending an email.– SirexFeb 11 at 20:12

cron will send the output of a process to whatever it is told to in the MAILTO variable. You can execute curl or find your IP with any number of tools.

More importantly you need to make sure that your system can send mail and have it accepted wherever you are intending to read it. If you get a public IP via DHCP your ISP might block SMTP, test this with something simple like a cron entry to send the hostname or some such.

    curl globalip.me | mail -s "my new ip" yourmail@example.com

    Here -s "my new ip" is subject of the message.You may want to try man mail for more options like email for 'CC' or 'BCC' fields etc.

      if you wish to have your internal network/private ip ( rather than the public one provided by the curl command in ~Putnik 's answer you could use

      ip r | grep -i wlp3s0 | grep -i src | cut -d' ' -f9 #note, the wlp3s0 interface name could/will be different on your machine

      then, as Putnik rightly answers, pipe that into mail...

      ip r | grep -i wlp3s0 | grep -i src | cut -d' ' -f9 | mail -s "$HOSTNAME new ip" yourmail@example.com

      next, we need to add this command to your crontab, so

      vim /etc/crontab

      and add to the last line...

      0 * * * * <$YOUR_USER_NAME> ip r | grep -i wlp3s0 | grep -i src | cut -d' ' -f9 | mail -s "$HOSTNAME new ip" yourmail@example.com 

      BONUS ::Cronjobs can fail! Monitor your important cronjob by pasting the following snippet at the end of the crontab entry. Make sure to replace the with your email address and some name for your cronjob.Should your cron job fail or not even start, you will receive an alert email.

      && curl -sm 30 k.wdt.io/<email-address>/<cronjob-name>?c=0_*_*_*_*

        Your Answer


        By posting your answer, you agree to the privacy policy and terms of service.

        Not the answer you're looking for? Browse other questions tagged or ask your own question.