Jump to content

Ifconfig To Email


Jamo

Recommended Posts

I just got an old pc from a friend and I decided to install ubuntu 11.10 server to it. Its just for ssh , websites. Its connected directly to internet, and it gets public ip address, no NAT.

So Iv got it working and I think that I got dyndns working with it too. Ip changes, aften 30+min offline, so I would like to make sure that I would have it's IP information all the time, just in case of dyndns issues :o.

So Iv created a script, that will run @restart, always when started.

basically that script dumps ifconfig to a file and uses sendEmail to send that file to my email.

ifconfig > ifconfigFile
sendemail "senders email, destination email, smtp server + ifconfigFile as attachment"

Well it's ok, but it would be easier if that ifconfig output would be in messages body, not as an attachment.

I would like to have the whole output, as it has teredo installed, so it has ipv4 and ipv6 addresses.

so any ideas, how to get ifconfig information sent to email, as the test will be in messages body, not as an attachment.

Link to comment
Share on other sites

Probably have to use variables of some sort, if sendmail can take arguments of variables instead of just sending the characters. Maybe something better than sendmail and instead a php form that you http post the data to, and populates the email with the data you want in the body of the email. I use php files to send me emails for various things, but you can also post to the php form and take argments and populate parts of the email. I use it to get ip addresses, OS, browsers user agents, etc, and email them to me. Just an idea though to use php, since it can basically hook into sendmail but if sendmail can take an argument, then use the output of ifconfig as a variable and paste it as the body.

Darren's last few hacker tips and episodes show some cli fu using variables, like his timestamp on the ping command output. See if that works.

Link to comment
Share on other sites

Well thanks to latest hak5 episode and some google-fu Iv solved my issue, heres the script Iv used:

#!/bin/bash

cd /home/USER
sleep 10
ip4=$(ifconfig | grep "inet")

sendemail -f "NAME SHOWN in from field <who@what.com>" -t target@email -u "[MESSAGE TITLE]"  -s mail.inet.fi:25 -m "$ip4" 

echo  $(date +%D) --- $(date +%T) >> /home/USER/scriptit/log/ifconfig.log

echo >> /home/USER/scriptit/log/ifconfig.log

Iv added some logging, but that works.

and in crontab Iv added (crontab -e)

@ reboot /path/to/that/file.sh

Edited by Jarmo
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...