curtis e. bear Posted February 14, 2005 Report Share Posted February 14, 2005 Can anyone help me create a script for me? It's pretty simple i think. All it needs to do it to do an ifconfig of my ppp0 > textfile, then email that file to my hotmail account, every day, this way i will be able to know the server's ip when i want to access it from over the internet, and won't get stuck when my isp decides to change my ip. I would really appreciate any ideas. [moved from Software by spinynorman] Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 14, 2005 Report Share Posted February 14, 2005 (edited) Hmmmm...think this needs to be in "Terminal Shell Commands, Kernel and Programming" for a better response, but I'll give it a shot: #!/bin/bash ifconfig | grep -A 3 ppp0 | tee /home/curtis/ifconfig | mailto -s ipaddress curtisebear@hotmail.com EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t mailip "ALERT exited abnormally with [$EXITVALUE]" fi exit 0 Name it mailip and put it in /etc/cron.daily, making it executable Edit: You need metamail installed. Edited February 14, 2005 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 14, 2005 Report Share Posted February 14, 2005 ifconfig | grep -A 3 ppp0 | tee /home/curtis/ifconfig | mailto -s ipaddress curtisebear@hotmail.com All of that should be on one line in case you don't copy and paste. Quote Link to comment Share on other sites More sharing options...
papaschtroumpf Posted February 14, 2005 Report Share Posted February 14, 2005 You should look into dynanic DNS (www.dyndns.org for example). Your server will automatically keep the DNS client informed of any IP change and you can access your server using a DNS name like myserver.dyndns.org. Probably a much better solution to your problem. Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 14, 2005 Report Share Posted February 14, 2005 Excellent idea. Also, check out no-ip.com for the same ability. Choice is always good. :D Quote Link to comment Share on other sites More sharing options...
aru Posted February 14, 2005 Report Share Posted February 14, 2005 (edited) Just stepping in :) The best expression to strip the ppp0 ip I know is this one: /sbin/ifconfig | awk '/P-t-P/ {print substr($2,6)}' Though this one is even clearer and faster (hence better): /sbin/ifconfig ppp0 | awk '/addr/ {print substr($2,6)}' Nothing new to add, just wanting to say hello Edited February 14, 2005 by aru Quote Link to comment Share on other sites More sharing options...
Guest anon Posted February 14, 2005 Report Share Posted February 14, 2005 I knew you would come with something aru, LOL Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 15, 2005 Report Share Posted February 15, 2005 (edited) Just stepping in :)The best expression to.... <<insert aru's boundless knowledge here>> <{POST_SNAPBACK}> yeahyeah :P I'm confused about the output of the two. I'll use my wlan0 as an example because I have no ppp: root@laptop.mdk /home/omar 1825 14-Feb-05> /sbin/ifconfig wlan0 | awk '/inet/ {print substr($2,6)}' 192.168.1.102 root@laptop.mdk /home/omar 1825 14-Feb-05 > /sbin/ifconfig wlan0 | awk '/addr/ {print substr($2,6)}' 192.168.1.102 root@laptop.mdk /home/omar 1825 14-Feb-05 > Why does the first one (supposedly slower) give me a new line after the ipaddr, but the second, faster, one gives me a new line before and after? Edited February 15, 2005 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
aru Posted February 15, 2005 Report Share Posted February 15, 2005 Why does the first one (supposedly slower) give me a new line after the ipaddr, but the second, faster, one gives me a new line before and after? Well, the first one is slower (In my example not in yours) because it parses the full ifconfig output while the second one (in my example again) only parses the ppp0 output :P The important thing about my second example is not that it's faster (the difference is minimal), but that is quite clearer because you can see w/o too much digging what the expression does, it gets ppp0 output and searchs for the "addr"ess inside. In the first example that wasn't clear at first sight (call me pedantic ) back to your question, in your second command (not in mine ) the "/sbin/ifconfig wlan0" has several lines with the string "addr" inside, but only one fits the rest of the awk expression (which is quite lucky), so all the other lines that are matching "addr" are printed as null to stdout. That doesn't happen with ppp0 because its output only has a single line that matches "addr" Here you'll see both your example, and the same command but printing instead all the lines that are matching the string "addr": ~$ /sbin/ifconfig eth0 | awk '/addr/ {print substr($2,6)}' 192.168.0.1 ~$ /sbin/ifconfig eth0 | awk '/addr/ {print $0}' eth0 Link encap:Ethernet HWaddr 00:02:44:5C:2E:E4 inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 Interrupt:10 Base address:0xac00 ~$ You'll better need to add ":" to your expression, as: ~$ /sbin/ifconfig eth0 | awk '/addr:/ {print substr($2,6)}' 192.168.0.1 ~$ Glad to see you all again :D Quote Link to comment Share on other sites More sharing options...
curtis e. bear Posted February 16, 2005 Author Report Share Posted February 16, 2005 So what if i just want to through the output of an ifconfig ppp0 into the body of an email and automatically send that to someone@somewhere.com (without any intervention after it has been setup) Also, would it be setup in atd or cron or what? Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 16, 2005 Report Share Posted February 16, 2005 (edited) #!/bin/bash ifconfig ppp0 | mailto -s ipaddress someone@someone.com EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t mailmyiptostranger "ALERT exited abnormally with [$EXITVALUE]" fi exit 0 Name it mailmyiptostranger and put it in /etc/cron.daily, making it executable This will not save it to a file first...just put it in the body of an email. The '-s ipaddress' part means 'subject'. Edited February 16, 2005 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
aru Posted February 16, 2005 Report Share Posted February 16, 2005 IMHO the best place to save that script is in /etc/ppp/ip-up.d, hence whenever you start/restart your internet connection you'll email the brand new IP. --> man pppd /etc/ppp/ip-up A program or script which is executed when the link is available for sending and receiving IP packets (that is, IPCP has come up). It is executed with the parameters interface-name tty-device speed local-IP-address remote-IP-address ipparam That ip-up script contains code to execute every script (run-parts) in /etc/ppp/ip-up.d HTH Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 16, 2005 Report Share Posted February 16, 2005 ahhh...shouldn't that be IMEO? :P (In My Expert Opinion) BTW: your English has improved remarkably and is now better than a lot of native English speakers I know. :D Quote Link to comment Share on other sites More sharing options...
curtis e. bear Posted February 20, 2005 Author Report Share Posted February 20, 2005 what needs to be installed for mailto to work, because i apparentley don't have it. Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted February 20, 2005 Report Share Posted February 20, 2005 Edit: You need metamail installed. <{POST_SNAPBACK}> 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.
Note: Your post will require moderator approval before it will be visible.