Solved Send email or text from script?

March 22, 2018 at 08:51:14
Specs: Windows 7
I'm running FreeBSD v11 at home. I wrote a script to check my external IP and if it changes, email myself and my friend to let us know that new IP. My provider has blocked the "send" command so that part of my script no longer works.

I've been doing some serious searching on the web to try and figure out how to get it working again. I should be able to login to my email from the BSD box with my credentials and send an email but I can't seem to get it to work. I'm hoping one of you guys here can help me with that.

Or.............get it to shoot me a text instead. My research also has lead me to believe having the script text me should work too but I'm unable to make that work either

Any ideas or tips?

Thanks

Curt

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***


See More: Send email or text from script?

Report •

✔ Best Answer
March 29, 2018 at 08:32:37
So far sending via email is a bust.....but further research and I've figured out how to send a text message to a cell phone via the command line....which I'm sure will work in a script.

These guys offer a free one month trial:

https://my.textmagic.com/login

and charge $4/month thereafter if you wish to stay with them.

NOTE: This requires "curl" be installed first

You have to download their tm.sh script....create an account with them and use it to generate a key. Finally, put the username and key inside the script. Drop the script in a pathed folder and you're ready to send texts.

I have yet to wire this into a script and try it. I had issues getting it working initially but then realized the problem was, the FreeBSD box I run my monitoring scripts on at work doesn't have internet access due to it being an OSPF stub (I have two interfaces running on it, one on my client network, the other on my management network. To make this work properly we had to install Quagga and make it an OSPF stub) Once I realized what the issue was, I downed the management network interface, created a static route for my client interface and was able to send a text from the command line.

I'm going to play with this at home where my FreeBSD box has only a single network interface enabled and direct internet access. If this will work for my script at home, then I'll run it on my monitoring scripts at work after moving the scripts to another box that isn't an OSPF stub.

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***



#1
March 22, 2018 at 09:09:42
If you are able to send E-Mails via your default E-Mail client, you should be able to send emails via shell script too.

If you are unable to send emails via E-Mail client, whats about using one of the free email provider to manage that?

So your script should work again, as expected.


Report •

#2
March 22, 2018 at 09:26:41
Without going into detail about what you've tired and what ISP you're going through, have you considered just using a free dynamic DNS?

How To Ask Questions The Smart Way


Report •

#3
March 22, 2018 at 10:00:54
@Razor2.3

I don't get it.
How can a free dynamic DNS help on this problem?


Report •

Related Solutions

#4
March 22, 2018 at 15:17:49
Hi Curt:

Are you trying to email from your FreeBSD account to an external account such as a windows account? If that is not working, it's because your ISP has disabled the mail not allowing external communication.

However, every bsd box I've been on has a mail or mailx command allowing email - at least on the FreeBSD box. If the email client is set up correctly, you should also be able to email to external accounts. This script example uses a HERE document as input to the mailx command:

# if mailing from one freebsd user to another on the same box,
# don't need the server name
TO="nails@freebsdbox"
SUBJECT="email test from unix/linux"


/usr/bin/mailx -s "${SUBJECT}" ${TO} << HERE
email test text.
Say what you want here

HERE
# continue with the rest of the script

Is this what you have been looking for? If mailx works for you on I can help you further with the script if you require it.


Report •

#5
March 23, 2018 at 04:14:56
The script was designed to send email to external (non-FreeBSD) clients. Originally when I created it, it would notify my friend in another province that my external IP had changed.

The script in question is one I asked about here previously:

https://www.computing.net/answers/u...

It sent email using the "mail" command. It used to work through my provider but doesn't anymore as they did something to shut down my ability to use "mail" from the command line (or within a script).

So my research on making this work again has lead me to believe I can actually use (from home) my ISP's email server to send again, I just have to connect to it using my email credentials. I just can't figure it out.

I've also been pursuing sending a text message to my cell phone using "curl" but I can't get that to work either.

Clear like mud? LOL

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***


Report •

#6
March 23, 2018 at 06:59:23
paulsep: How can a free dynamic DNS help on this problem?
Depends on if the overarching question is, "How can I be notified that my IP has changed?" or, "What is my home PC's IP?" If it's the latter, answering, "Donno, ask DNS," is an easy answer.

I just ask because there's a noip.com client for FreeBSD, and if you have a router that'll automatically update dynamic DNS for you, everything's simplified.

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#7
March 29, 2018 at 08:32:37
✔ Best Answer
So far sending via email is a bust.....but further research and I've figured out how to send a text message to a cell phone via the command line....which I'm sure will work in a script.

These guys offer a free one month trial:

https://my.textmagic.com/login

and charge $4/month thereafter if you wish to stay with them.

NOTE: This requires "curl" be installed first

You have to download their tm.sh script....create an account with them and use it to generate a key. Finally, put the username and key inside the script. Drop the script in a pathed folder and you're ready to send texts.

I have yet to wire this into a script and try it. I had issues getting it working initially but then realized the problem was, the FreeBSD box I run my monitoring scripts on at work doesn't have internet access due to it being an OSPF stub (I have two interfaces running on it, one on my client network, the other on my management network. To make this work properly we had to install Quagga and make it an OSPF stub) Once I realized what the issue was, I downed the management network interface, created a static route for my client interface and was able to send a text from the command line.

I'm going to play with this at home where my FreeBSD box has only a single network interface enabled and direct internet access. If this will work for my script at home, then I'll run it on my monitoring scripts at work after moving the scripts to another box that isn't an OSPF stub.

It matters not how straight the gate,
How charged with punishments the scroll,
I am the master of my fate;
I am the captain of my soul.

***William Henley***


Report •

Ask Question