LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-02-2016, 11:40 AM   #1
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,543

Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Looking for advice on some odd cron MAILTO behavior


I got a request the other day to have the crontab for a service-related account on a Linux system (RHEL 6.6) begin using an email alias that was created for a team. Seemed simple enough. Only take a couple of minutes. Right?

Currently, that crontab has a line like:
Code:
MAILTO=bob@mega.com,carol@mega.com,ted@mega.com,alice@mega.com
which they'd like to be changed to:
Code:
MAILTO=Development&TestGroup@mega.com
The trouble is that it doesn't work. The result of any MAILTO that contains an ampersand gets you the equivalent of
Code:
MAILTO=""
which, of course, disables the sending of emails when cron jobs are run.

The alias itself does work when I issue:
Code:
echo "Test. Please ignore." | mailx -r Test Development\&TestGroup@mega.com
so the ampersand itself isn't illegal as part of an email address. (It's just annoying to the 'ix user who has to remember to escape it.)

I've come to the conclusion that it may not be possible to use such an email alias in cron's MAILTO variable. What I've tried:
Code:
MAILTO=Development\&TestGroup@mega.com    (works in the shell so...)

MAILTO="Development&TestGroup@mega.com"   (tried w/ and w/o escaping)

MAILTO='Development&TestGroup@mega.com'   (single quotes prevent special interpretation, right?)

MAILTO=Development%26TestGroup@mega.com   (A real longshot. 26h = &. Tried this w/ and w/o escaping the '%'.)
as well as some other combinations of the above.

Perhaps the most interesting/frustrating/confusing thing I've been seeing during testing is that even a commented out MAILTO containing an ampersand will kill emails. For example, during testing I had been using something like:
Code:
#MAILTO=bob@mega.com,carol@mega.com,ted@mega.com,alice@mega.com
MAILTO=Development\&TestGroup@mega.com
and when my testing wasn't getting the result I was looking for, I decided to revert back to the original MAILTO by using:
Code:
MAILTO=bob@mega.com,carol@mega.com,ted@mega.com,alice@mega.com
#MAILTO=Development\&TestGroup@mega.com
Result? No emails. I had to completely remove the commented out MAILTO containing the ampersand for normal cron email behavior to be restored. After forcing the SHELL variable to "/bin/bash" (from the default of "/bin/sh") I found that I could then merely comment out the MAILTO that wasn't working. (Why /bin/sh would make cron work differently is a puzzler for another day.)

So far I've found nothing about any limitations on what is allowable in a MAILTO setting but it sure looks like it doesn't follow normal shell interpretation of certain punctuation characters. We already know that '%' can be problematic in cron records but I've not seen anything mentioned -- nor have my searches using The Google come up with any -- that say there's anything special about how cron deals with ampersands.

Q: Is this a hopeless and impossible request I've received?

Q: Has anyone had to use the ampersand in their MAILTO setting before and, if so, how did you get it to not clobber emailing?

Any hint, tips, or suggestions are enthusiastically welcomed.

TIA...

--
Rick
 
Old 04-02-2016, 07:42 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora 34
Posts: 3,733

Rep: Reputation: 1091Reputation: 1091Reputation: 1091Reputation: 1091Reputation: 1091Reputation: 1091Reputation: 1091Reputation: 1091
My guess is you are getting the '&' into the MAILTO variable, but that cron is calling system() to issue the mail command, and that the system-called shell is balking. See if you can set it to a string that includes escapes or quotes;
Code:
MAILTO=Development\\&TestGroup@mega.com
or
MAILTO="'Development&TestGroup@mega.com'"
 
Old 04-02-2016, 09:11 PM   #3
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Older: Coherent, MacOS, Red Hat, Big Iron IXs: AIX, Solaris, Tru64
Posts: 2,543

Original Poster
Rep: Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511Reputation: 511
Quote:
Originally Posted by smallpond View Post
See if you can set it to a string that includes escapes or quotes;
Code:
MAILTO=Development\\&TestGroup@mega.com
or
MAILTO="'Development&TestGroup@mega.com'"
Worth a try, I guess. Somehow I doubt that fully explains what's going on where a commented out MAILTO that contains an ampersand prevents mails from being sent out. Even when there's a working MAILTO in the crontab. As I think I mentioned, though, ensuring that the SHELL was set to /bin/bash as opposed to the default /bin/sh managed to keep the contents of the commented out, ampersand-containing MAILTO from affecting mail delivery. I'm thinking of tracking down the source code for the version of cron that Red Hat shipped with RHEL 6.6 to see if I can figure out how the MAILTO setting is being handled. Boy, that should be some fun.

I'll probably not be posting the results of any tests using your suggested syntax until Monday though I could try fanagling an alias with an ampersand in it on a home system to see if I can duplicate the problem on OpenSUSE that I'm seeing on RHEL. (If someone sees me logged into work on the weekend...)

Thanks for the suggestions...

--
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
funky cron.d odd behavior DirtyHowi Linux - General 1 09-02-2014 12:10 AM
Odd cron behavior with CentOS5 jakev383 Linux - General 4 04-30-2008 11:34 AM
cron & MAILTO mikeshn Linux - Software 1 04-17-2006 05:06 AM
Cron + MAILTO option mikeshn Linux - Software 1 10-19-2004 07:31 AM
cron mailto eyt Linux - Newbie 3 02-17-2004 08:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration