PDA

View Full Version : Mail from shell



crazy8
26th December 2008, 07:53 PM
Im sure I did this once before at my last employer. Anyway I have a server set up at home running Windoze 2k3 running FC10 as a VM via VMWare. I am trying to create a script that when exicuted it will mail a file "current_ip.txt" to my yahoo account. How would I go about doing this?
I have tried mutt and cant seem to get that to work since it generates 553 errors. Im not sure how to fix that but im sure that would be the easiest thing to do. Any suggestions or help on this would be greatly appreciated. Also I have tried sendmail and mail both with no luck.
Are there any prerequisites to setup before I do this that Im not aware of other than installing Linux?

Thanks alot.

scottro
27th December 2008, 12:51 AM
You have to have some sort of smtp agent working, be it sendmail, postfix, or something light.

I have a page on mutt that also goes into configuring msmtp to work with it, which might be of use?

http://home.roadrunner.com/~computertaijutsu/mutt.html

JN4OldSchool
27th December 2008, 01:00 AM
Hey Scott, can I make a request of you? I use your wpa supplicant page all the time. I went to my bookmark and the link is now broken. I have relocated it through searching your posts, but could you put your site (main page) in your signature? I know you are modest about these things but it is one of the most informative general Linux sites I have found, full of valuable info. You really should link it in your sig.

stlouis
27th December 2008, 01:35 AM
Just out of curiousity, why are you trying to setup a script that will email you the "current ip" of your server. That's not usually a very secure thing to do...

Is you server connected directly to the Internet, acting as your router?

It almost sounds like your are setting up something similar to what DDNS does for you...

Anyhow, you don't have to setup a l0cal Mail Server in order to use "mutt" to send email... The easiest setup will be to use the IMAP or Secure IMAP service, then proceed via that method... I assume you are configuring it to run the script via your CRON/AT ...

Here's a few links to get you started..

http://mutt.sourceforge.net/imap/

http://www.mutt.org/doc/manual/manual-4.html (near the end)


What mail server are you forwarding these messages through for delivery? You own or an external mail server such as your ISP's? As you would have to ensure the IMAP Protocol is supported...

Otherwise, setup POSTFIX as a Mail Relay server... This should take no more than 15 minutes... If external, you will most likely have to setup authentication, which isn't much...

If you want the instructions on con figuring a Postfix Mail relay, let me know... I set these up all the time for clients of mine, on CentOS, however Fedora should be identical..

I'm a big postfix fan... Zimbra is Mail Server of preference, which also use's postfix as it's backend...

GrapeShot
27th December 2008, 01:50 AM
This works for me. You will have to make it into a cron job though.


#/bin/bash
/sbin/ifconfig eth0 | grep inet > changed_ip.txt
mutt -s "IP" your@address.com < /path/to/changed_ip.txt

scottro
27th December 2008, 03:21 AM
@Jn4, it moved--I put big notes on the most popular pages, as roadrunner gave me about 3 weeks warning, but I guess you missed that window. :)

http//home.roadrunner.com/~computertaijutsu is the new page. I think it's in my profile, which I think can be viewed.


Edit


Oh, it was't. It is now.

crazy8
27th December 2008, 05:27 AM
@stlouis
I came up with an idea that I wanted to integrate into my server somehow. Here is the deal. I dont have any server side computer programming knowledge other than php. My idea was that we have a dynamic ip through our ISP. Since it is dynamic it will change every three to six months. So since I remote into my server it would be nice to know what my server's IP Address is once it changes. Of course I will not know exactly when it changes so I thought of writing a script(s) that would send me an email everyday on what the current ip is. Another option would be to run the one line script I have now, every day and once it changes then mail me the new one.
I hope I have made since of what I am trying to do. I know that this isnt the most secure thing but how else would you find out your servers external IP Address if it was static. I know the easiest thing to say here is "get a static ip" but thats not an option as its my dads house and his money.

I dont remember if I mentioned it before but if it helps at all im trying to send mail (only send) from my server to my yahoo account

Thank you all so much for your help.

GrapeShot
27th December 2008, 05:55 AM
I came up with an idea that I wanted to integrate into my server somehow. Here is the deal. I dont have any server side computer programming knowledge other than php. My idea was that we have a dynamic ip through our ISP. Since it is dynamic it will change every three to six months. So since I remote into my server it would be nice to know what my server's IP Address is once it changes. Of course I will not know exactly when it changes so I thought of writing a script(s) that would send me an email everyday on what the current ip is.

I do similar stuff - dynamic IP on a server that I can access from work. Take a look at dyndns.com. They provide a dynamic DNS service that will map your IP to a name that you can choose. Fedora provides a client called inadyn (yum install inadyn) that monitors your dynamic IP address and when it changes, it updates your record at dyndns.org. From work you could then access your server by name then instead of IP.

Another way of finding out your currently assigned IP address is to go to http://checkip.dyndns.com - that is the site that a lot dyndns clients use to get a users IP.

Brian1
27th December 2008, 07:45 AM
I wish I had my linux firewall up so i get what i use.. Here is something i have on my notebook till i get home and boot the firewqall up. I know not what you really asked but I check the ip on boot and then compare every 5 minutes if it changes. If it changes it sends and email. It will always send an email when first booting up for reference.

What is my Public IP Address?
* * * 5 votes
Extra pice of finding local IP info.
ifconfig eth0 | grep inet | cut -d : -f 2 | cut -d \ -f 1
http://linux.byexamples.com/archives/307/what-is-my-public-ip-address/
August 22nd, 2007 mysurface Posted in egrep, curl, grep, wget, Text Manipulation, Misc | Hits: 22593 |
What is my public IP address? There is a lots of website can provide you the information. What if I wanna grep it for my script? We can use curl and grep for this purpose.
First, lets pick few websites that provide the service to reveal my public IP.
http://www.ipchicken.com/ - the chicken looks so funny.
http://whatismyip.com/ - a guy playing VR game.
http://myip.dk/ - a simple website but served the purpose.
Next, lets crawl the page and grep the IP
curl -s http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
You can use wget if you do not install curl
wget -qO - http://myip.dk/ | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
The important part is the regex. [0-9] indicate any digit within 0 - 9 and {1,3} indicate it should appear minimum 1 time, maximum 3 times. -o indicate grep to print the matched part and -m1 is to limit the grep process to stop at first match.
http://whatismyip.org/ - no need to grep, just curl it.
curl -s http://whatismyip.org/
It seems that getting public IP from http://whatismyip.org/ is far more convenient, the limitation is that you are allow to access the page only 3 times within 10 minutes.
After all, I just enjoy greping with regex :)
[中文翻译]
Related Posts
Save typing using vi abbrevations
Do you find yourself typing some long text too often that it's getting tiresome (especially when it comes to hard to rem...
ssh reverse tunneling
Recently I just discover how to perform ssh reverse tunneling, which is so amazing! I though I know enough about ssh, bu...
ssh server security warning
If you are hosting your ssh server to public, please remember to disable the root access. This is important! A lots of "...
4 Responses to “What is my Public IP Address?”
1.
bla Says:
August 24th, 2007 at 9:38 pm
Cool!
This one is for the ‘visually impaired’ users:
mpg123 “http://moanmyip.com/output/$(curl http://www.moanmyip.com | egrep -m1 -o ‘[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}’).mp3″
Cheers. ;)
2.
hehe Says:
September 16th, 2007 at 4:37 pm
myip.dk and ip-adress are the old ones dunno how i even remember that ;S
check http://www.iplobster.com - cunning lobster hehe but i needed ipv4 info
3.
ching Says:
October 30th, 2007 at 6:07 am
this is a great piece of work. Good job man and a great website
4.
A New Day Has Come Blog Archive bash tips Says:
November 27th, 2007 at 12:01 am
[…] 我的公网IP是多少? curl -s http://myip.dk/ | egrep -m1 -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’ wget -qO - http://myip.dk/ | egrep -m1 -o ‘[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}’ curl -s http://whatismyip.org/ […]
Leave a Reply
Name (required)
Mail (will not be published) (required)
Website

crazy8
27th December 2008, 03:59 PM
@GrapeShot
Thanks alot for telling my about dyndns. I have that setup and it works like a charm. so instead of typing in xxx.xxx.xxx.xxx in "mstsc" on a windoze machine all I have to do now is type in mydomain.homelinux.com So now that I have that taken care of Im trying to find a reason no to uninstall my linux vm. Im suree Ill keep it because I know something will come up ;)

Thanks again