LinuxQuestions.org
Visit Jeremy's Blog.
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 11-25-2011, 04:32 AM   #1
kalpesh chhajed
LQ Newbie
 
Registered: Nov 2011
Posts: 6

Rep: Reputation: Disabled
problem in adding attachment in crontab


i am using cronatb file to execute the task automatically. after executing the task the output is mailed to the one that is specified in MAILTO field in crontab file but i want to mail another file not the output file that is generated after executing the command.
or can we add attchment as another file in crontab which will be mailed after execution.
please suggest some useful options...
your help is appreciated..
thanks..
 
Old 11-25-2011, 05:33 AM   #2
bluesatbridge
Member
 
Registered: Oct 2010
Location: england
Distribution: debian , redhat
Posts: 36

Rep: Reputation: 2
man page of cron says . It might be useful to you

In addition to LOGNAME, HOME, and SHELL, cron will look at MAILTO if
it has any reason to send mail as a result of running commands in
`this' crontab. If MAILTO is defined (and non-empty), mail is sent to
the user so named. If MAILTO is defined but empty (MAILTO=""), no mail
will be sent. Otherwise mail is sent to the owner of the crontab. This
option is useful if you decide on /bin/mail instead of /usr/lib/sendmail
as your mailer when you install cron -- /bin/mail doesn't do aliasing,
and UUCP usually doesn't read its mail.


so what i understand is u can try editing the crontab file and put this entry there

crontab -e
and add this entry
MAILTO=user@domain.com

hope this works
 
Old 11-25-2011, 05:48 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by kalpesh chhajed View Post
but i want to mail another file not the output file that is generated after executing the command.
I'm not aware of any method to make the CRON daemon send an attachment. You have two other options anyway:

1. explicitly send an e-mail to recipient $MAILTO from inside the script or at the end of the cron job, e.g.
Code:
0 4 * * * /path/to/my/job.sh && mutt -s "Subject" -a /path/to/attachment $MAILTO
2. If it is a text file you can send its content to the standard output
Code:
cat /path/to/file.txt
so that it will be displayed in the mail body together with the usual output.
 
Old 11-25-2011, 05:51 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...or just execute sending the attachment fron your cronjob:
Code:
#!/bin/sh
# Don't mail output
MAILTO=""
# Use mktemp for temporary files
TMPFILE=`mktemp -p /tmp cronjob.XXXXXXXXXX` && {
 # Generate output and place it in the temporary file
 /bin/ps ef > "${TMPFILE}"
 # If the temporary file is not empty, use 'mpack' to send the file off as attachment:
 [ -s "${TMPFILE}" ] && mpack -s "Subject_here" "${TMPFILE}" recipient@ho.st
 # Clean up
 rm -rf "${TMPFILE}"
}
# Exit properly
exit 0
 
  


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
convert email files with attachment to save as attachment file (metamail?) ted_chou12 Linux - Software 2 04-08-2011 09:01 PM
bad minute error adding a crontab job htamayo Linux - Newbie 7 03-15-2010 09:56 AM
How to send a html file as an file attachment to my mail from crontab? GRD Linux - Newbie 2 06-03-2008 12:39 PM
ezmlm attachment problem k3di Linux - Software 0 06-02-2004 06:08 AM
adding a job to crontab via shell script tazio Linux - General 7 10-23-2003 03:44 PM


All times are GMT -5. The time now is 02:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration