Jamo Posted November 5, 2011 Share Posted November 5, 2011 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. Quote Link to comment Share on other sites More sharing options...
digip Posted November 6, 2011 Share Posted November 6, 2011 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. Quote Link to comment Share on other sites More sharing options...
i8igmac Posted November 6, 2011 Share Posted November 6, 2011 http://www.tutorialspoint.com/ruby/ruby_sending_email.htm You can find these examples in almost any language, I like ruby so here is how I would do it. I could maybe write something tonight. This will get you started Quote Link to comment Share on other sites More sharing options...
Jamo Posted November 6, 2011 Author Share Posted November 6, 2011 (edited) 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 November 6, 2011 by Jarmo Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.