Sending EMail from Script Running in Jail

Status
Not open for further replies.

nello

Patron
Joined
Dec 30, 2012
Messages
351
I have a bash script in a MythTV Jail and I want it to email the log that it produces. I've seen several threads about sending email from scripts running on FreeNAS, but none in which the script runs in a Jail.

For example, consider this command:
Code:
echo "body" | mail -s "subject" myVerizonPhoneNumber@vtext.com



When entered on the FreeNAS terminal (logged in as root), I receive a text.

When entered on the MythTV Jail terminal (logged in as root), I receive nothing even though there is no error.

How do I send an email from within a script running in a Jail?
 

nello

Patron
Joined
Dec 30, 2012
Messages
351
Is sendmail running in the jail?

I don't know; how can I tell whether sendmail is running?

Or, more generally, is software to send mail included as part of creating a Jail (through the FreeNAS GUI)?
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Set it up as a task from the FreeNAS GUI. Just add jexec yourjailname and then your script to run.
 

nello

Patron
Joined
Dec 30, 2012
Messages
351
Set it up as a task from the FreeNAS GUI. Just add jexec yourjailname and then your script to run.

I like that this piggybacks on the FreeNAS configuration, rather than installing/configuring mail within the Jail.

But, I want the script within the Jail to initiate the email. (I'm running a post-processing script in a MythTV Jail. This script creates a log of what it's done and I want the script to email the log if it encounters certain conditions.)

Is there someway for the Jail script to reach out to FreeNAS to send a mail message? Can a Jail script trigger a FreeNAS Task? Another way?

Thank you.
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Not sure, hopefully some of the more knowledgable members can chime in. Scripting is something I'm not very good at at all. I would think that you should be able to set up a task to attach the log file and email or text it and set it to run at a pre set time when you know it's complete.
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Well after playing around with this for a bit I got something to work. You would have to set it as a scheduled task to run at a pre set time from the GUI but I was successful in emailing an attached file. Sending it via text did not work.
Code:
uuencode pathtoyourfile yourfilename | mail -s "test"  youremail


To get something to run from within the jail triggered by a script is going to likely require you to configure sendmail or another mail agent within the jail. Mutt seems to be another option for attachments but again your still going to need a mail agent configured inside the jail to make it work.
 
Last edited:

ovizii

Patron
Joined
Jun 30, 2014
Messages
435
to piggyback on this question with a related one:

so there#s no chance of having a cron job run inside a jail and email results either without installing a full-blown email stack in the jail?
 

Jailer

Not strong, but bad
Joined
Sep 12, 2014
Messages
4,977
Found something today while digging around on another subject that might be what you are looking for.

Dragonfly Mail Agent
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
to piggyback on this question with a related one:

so there#s no chance of having a cron job run inside a jail and email results either without installing a full-blown email stack in the jail?

Install mini_sendmail ...
 

nello

Patron
Joined
Dec 30, 2012
Messages
351
I REALLY don't want to install/configure a Mail Transfer Agent (MTA) ... much less in my MythTV jail.

So, decided to try this approach:
  1. Script kicked off by MythTV post-processing options does its thing and creates a log.
  2. If the script decides the log should be mailed, then it copies the log to a directory that serves as a mail queue.
  3. Task (cron job) in FreeNAS gui kicks off its own script every hour; the Task script looks in the queue directory and for each file in the queue directory, the Task:
    • Mails the log file, and
    • Deletes the log file
Does this sound reasonable? Potential pitfalls? Suggestions for improvements?
 
Last edited:

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
mini_sendmail is not an MTA, its a tiny program that just submits mail from scripts to a mailhost.
 

nello

Patron
Joined
Dec 30, 2012
Messages
351
mini_sendmail is not an MTA, its a tiny program that just submits mail from scripts to a mailhost.

Thank you for the clarification.

I presume this is what you are recommending:
http://acme.com/software/mini_sendmail/

I took at the website and it appears to be C code that I'd have to build/install/maintain on my FreeNAS.

It seems to do exactly what I need ... but I'm not comfortable building C code and will take a pass on this approach.

Thank you for your suggestion. I'm sure it would be helpful for someone more technically adept.

- nello
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
It's not difficult to build/install/maintain. But as you wish.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Here is the link I'd start with since it actually gives you the steps to build/install the mini_sendmail application and the location to download it (you already listed above). As @jgreco said, it's not difficult at all to install.

The solution you were doing above, if it works and you are happy with it then I say use it, it just seems a bit more complicated overall but if you have already done the work then why mess with it.
 

jgreco

Resident Grinch
Joined
May 29, 2011
Messages
18,680
Yup. There's no shortage of ways to send mail without an MTA. You can even use netcat if you're sufficiently clever, and avoid even an MSA!
 

nello

Patron
Joined
Dec 30, 2012
Messages
351
Here is the link I'd start with since it actually gives you the steps to build/install the mini_sendmail application

Sorry, I don't see a link in your message.
 

joeschmuck

Old Man
Moderator
Joined
May 28, 2011
Messages
10,994
Status
Not open for further replies.
Top