LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-20-2010, 09:28 AM   #1
ahingert
LQ Newbie
 
Registered: Aug 2010
Posts: 22

Rep: Reputation: 0
Cron email with attachment


Hi,
I hope somebody will be able to help me.

I am running a Cron job which mails the content of a log report every day. The problem is that the contents are sent as an attachment instead of as the body of the email. The strange thing is that if I run the instructions from the command line everything works fine, but if I do so from the Cron job the log report is attached instead of being sent inline.

The instruction I use is:
Code:
mail -s "logfile for cron" cron@example.com </var/log/cron-log
Following some advice I read on a blog I also tried this instruction in my Cron file, but the result is the same: it works fine from the command line, but attaches the report when run from Cron:
Code:
echo "Content-Type: text/plain;" | mail -s "logfile for cron" cron@example.com </var/log/cron-log
Does anybody know how to ensure the content of the log file is inline?


Thanks,
Adrien
 
Old 09-20-2010, 10:19 AM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
You might be using two different mail programs. Find out which one you're using from the command line:
Code:
which mail
and specify its full pathname in the crontab.
 
Old 09-21-2010, 12:12 PM   #3
ahingert
LQ Newbie
 
Registered: Aug 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Hi Berhanie,
I tried what you said and found that the mail program was "/bin/mail" and used this path in my Cron script. The result is however the same: the log report comes as an attachment.


Do you have any other suggestion?


Thanks,
Adrien
 
Old 09-21-2010, 01:46 PM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
/bin/mail, so far as i am aware, isn't capable of MIME, and so cannot send attachments by itself. maybe you can examine the headers of the two mails (commandline- and cron-generated) for clues. it may be that you're not sending the exact email both times, or that you're using two different mail clients to read them.
 
Old 09-21-2010, 02:11 PM   #5
ahingert
LQ Newbie
 
Registered: Aug 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Interesting, the headers tell me that:
Code:
User-Agent: Heirloom mailx 12.4 7/29/08
Isn't this another mail program?
 
Old 09-21-2010, 02:18 PM   #6
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
yes. heirloom/mailx is capable of sending attachments (mailx -a file1 ...). do you see the header in both emails?
 
Old 09-21-2010, 02:34 PM   #7
ahingert
LQ Newbie
 
Registered: Aug 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Sending it from the command line I get the same user agent, but the encoding is different.

from the command line I get:
Code:
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
While from the Cron job I get:
Code:
Content-Type: application/octet-stream
Content-Transfer-Encoding: 8bit
Any ideas?
 
Old 09-21-2010, 03:09 PM   #8
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
The third item in this changelog says:
Code:
* When the text of an outgoing message contains illegal byte sequences
  in non-interactive mode, do not refuse sending it but send it with
  the "application/octet-stream" content type instead...
That explains how an inline message can get converted to an attachment. Now, you might
examine either the file you're sending or your crontab script for the origin of non-ascii
characters.
 
Old 09-21-2010, 04:08 PM   #9
ahingert
LQ Newbie
 
Registered: Aug 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Excellent, you've hit it right on the head: the problem was that I was including the Euro symbol in the report. I guess removing this should solve the problem. I will be reporting back.


Thanks,
Adrien
 
Old 09-22-2010, 01:31 AM   #10
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,355

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Another option: try using a sub-process
Code:
(cat file.log)| mailx -s "subj..." user@addr.com
 
Old 09-22-2010, 01:53 AM   #11
ahingert
LQ Newbie
 
Registered: Aug 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Thanks Chrism01, I'll try that as well.

@Berhanie: removing the Euro symbol did the trick, thanks!
 
Old 09-22-2010, 09:52 AM   #12
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
good to know, ahingert.
 
  


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
C code for Sending Email with attachment Mr coder Programming 5 03-07-2009 12:21 PM
C code for Sending Email with attachment Mr coder Linux - Newbie 1 03-06-2009 06:25 AM
email attachment lhrt Linux - Networking 3 05-31-2006 05:13 AM
cannot receive email with attachment charles168 Linux - Software 2 09-06-2003 09:43 AM
Send Email + Txt Attachment Using Cron Job beringer Linux - Newbie 3 01-31-2003 10:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:50 AM.

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