LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-04-2012, 07:16 PM   #1
Linux_Newbee83
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Rep: Reputation: Disabled
Syntax for : Receiving email once Cron job is completed


I'm new to Linux and this thread as well. I read many answers on this forum but still not clear about the answer.

What I'm looking for is:
I have a cron job that does backup of some data. It runs daily from around 9pm-10pm. So is there a way I can receive a COMPLETE notification email once that cron job gets completed successfully?? I'm really not sure about syntax of code..

Thanks once again.
 
Old 01-04-2012, 08:13 PM   #2
novice06
Member
 
Registered: Mar 2006
Location: Singapore
Distribution: RHEL, CentOS
Posts: 132

Rep: Reputation: 23
# use /bin/sh to run commands, no matter what /etc/passwd says
SHELL=/bin/sh
# mail any output to `paul', no matter whose crontab this is
MAILTO=paul
#
# run five minutes after midnight, every day
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
# run at 2:15pm on the first of every month -- output mailed to paul
15 14 1 * * $HOME/bin/monthly
# run at 10 pm on weekdays, annoy Joe
0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
5 4 * * sun echo "run at 5 after 4 every sunday"

ref:
http://crontab.org/
 
Old 01-04-2012, 08:21 PM   #3
Gomer_X
LQ Newbie
 
Registered: Jan 2012
Location: Ohio
Distribution: Debian, CentOS, Fedora, LFS
Posts: 24

Rep: Reputation: Disabled
Quote:
Originally Posted by Linux_Newbee83 View Post
I have a cron job that does backup of some data. It runs daily from around 9pm-10pm. So is there a way I can receive a COMPLETE notification email once that cron job gets completed successfully??
Any output from a script run in cron will automatically be sent as an E-mail to root. If whatever you're using for backup has a verbose option use that. Otherwise run it from a script that outputs what you need.
 
Old 01-04-2012, 09:04 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,493

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
But you have to configure you MTA correctly in order to send the e-mail to an external address, that is outside the machine you are using. That is called a smarthost.

I hope you are using Ubuntu, so in a terminal type
Code:
dpkg-reconfigure exim4
http://www.glorat.net/2008/11/ubuntu...ith-exim4.html

Then in the /root directory create a file .forward (Note the decimal point in front of the filename)
The file contents is simply:
you@wahtever.com

jlinkels

Last edited by jlinkels; 01-04-2012 at 09:13 PM.
 
Old 01-04-2012, 09:11 PM   #5
Gomer_X
LQ Newbie
 
Registered: Jan 2012
Location: Ohio
Distribution: Debian, CentOS, Fedora, LFS
Posts: 24

Rep: Reputation: Disabled
Quote:
Originally Posted by jlinkels View Post
But you have to configure you MTA correctly in order to send the e-mail to an external address, that is outside the machine you are using.
Correct. But the OP didn't say they wanted to do that. Obviously an MTA will have to be set up properly in any case.
 
Old 01-04-2012, 10:11 PM   #6
Linux_Newbee83
LQ Newbie
 
Registered: Jan 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you everyone..I will let you all know once I implement.
 
  


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
cron job sends email mdg Programming 2 12-26-2009 04:40 AM
Blank email on Cron job Taleya Linux - Newbie 3 12-19-2007 08:52 PM
Cron Job Syntax for a task in seconds AJones Linux - Software 2 07-22-2005 01:56 PM
cron job email results... ryedunn Linux - General 7 01-26-2005 11:27 PM
Cron job , send email mikeshn Linux - General 1 09-21-2003 10:02 AM


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