LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices

Reply
 
Search this Thread
Old 10-09-2012, 06:37 PM   #1
khandu
Member
 
Registered: Sep 2003
Posts: 79

Rep: Reputation: 0
Question Get email from crontab on success RHEL6


So a n00b

We run a couple of crontab as user "cronuser" on RHEL 6

although the crontab runs.. when I login to the machine as testing and type

mail

that is empty and says no email for the user "cronuser"

I assumed that on successful run of crontab it send an email to the user@machine box..

We had setup a file called .forward in the home directory of user "cronuser" with an external email address.. so that it send out all success run email of crontab to a mailing list...

this method was working for us in solaris.. not in RHEL6

How do we set this up? Basically we want to be notified to an external email address everytime crontab runs..
 
Old 10-09-2012, 07:12 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Quote:
Originally Posted by khandu View Post
I assumed that on successful run of crontab it send an email to the user@machine box..
Cron sends email to the crontab owner on error or if messages get sent to stderr / stdout, and if the MAILTO variable isn't unset.
 
Old 10-09-2012, 07:18 PM   #3
khandu
Member
 
Registered: Sep 2003
Posts: 79

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
Cron sends email to the crontab owner on error or if messages get sent to stderr / stdout, and if the MAILTO variable isn't unset.
So how to get email on every success .. if the scripts being run by crontab are sending messages to stderr / stdout then .forward should work??

I have a crontab

* * * * * ping 127.0.0.1

Still no emails in mailbox of user or to external address via .forward

Last edited by khandu; 10-09-2012 at 07:34 PM.
 
Old 10-09-2012, 07:34 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Quote:
Originally Posted by khandu View Post
if the scripts being run by crontab are sending messages to stderr / stdout then .forward should work??
Instead of asking you could test that yourself.
 
Old 10-09-2012, 07:35 PM   #5
khandu
Member
 
Registered: Sep 2003
Posts: 79

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
Instead of asking you could test that yourself.
I have a crontab
Quote:
* * * * * /bin/ping 127.0.0.1
Still no emails in mailbox of user or to external address via .forward

Last edited by khandu; 10-09-2012 at 07:40 PM.
 
Old 10-09-2012, 08:23 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
OK.
Does the cron daemon actually run?
What does 'crontab -l 2>&1' return for this user?
And 'cat /var/spool/cron/user? (Subst. account name.)
Are there /etc/cron.{deny,allow} files and if so is the user listed in any of them?
Are there any messages related to his account or crontab in /var/log/{messages,cron,secure}* or /var/log/audit/audit.log?
 
Old 10-09-2012, 08:43 PM   #7
khandu
Member
 
Registered: Sep 2003
Posts: 79

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
OK.
Does the cron daemon actually run?
What does 'crontab -l 2>&1' return for this user?
Code:
crontab -l 2>&1
* * * * * /bin/ping 127.0.0.1
Quote:
And 'cat /var/spool/cron/user? (Subst. account name.)
Code:
* * * * * /bin/ping 127.0.0.1
Quote:
Are there /etc/cron.{deny,allow} files and if so is the user listed in any of them?
cron.allow does not exist and cron.deny is empty

Quote:
Are there any messages related to his account or crontab in /var/log/{messages,cron,secure}* or /var/log/audit/audit.log?
audit.log has mesasges like

Quote:
type=CRED_ACQ msg=audit(1349833211.871:39503): user pid=10366 uid=500 auid=500 ses=2 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:setcred acct="user" exe="/usr/bin/crontab" hostname=? addr=? terminal=cron res=success'
type=USER_ACCT msg=audit(1349833261.288:39511): user pid=10398 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 msg='op=PAM:accounting acct="user" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success'
type=CRED_ACQ msg=audit(1349833261.288:39512): user pid=10398 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 msg='op=PAM:setcred acct="user" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success'
type=LOGIN msg=audit(1349833261.292:39513): pid=10398 uid=0 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 old auid=4294967295 new auid=500 old ses=4294967295 new ses=346
type=USER_START msg=audit(1349833261.301:39514): user pid=10398 uid=0 auid=500 ses=346 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 msg='op=PAM:session_open acct="user" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success'
type=USER_ACCT msg=audit(1349833321.292:39515): user pid=10415 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 msg='op=PAM:accounting acct="user" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success'
type=CRED_ACQ msg=audit(1349833321.296:39516): user pid=10415 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 msg='op=PAM:setcred acct="user" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success'
type=LOGIN msg=audit(1349833321.297:39517): pid=10415 uid=0 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 old auid=4294967295 new auid=500 old ses=4294967295 new ses=347
type=USER_START msg=audit(1349833321.302:39518): user pid=10415 uid=0 auid=500 ses=347 subj=system_u:system_r:crond_t:s0-s0:c0.c1023 msg='op=PAM:session_open acct="user" exe="/usr/sbin/crond" hostname=? addr=? terminal=cron res=success'
/var/log/cron has

Quote:
Oct 10 12:41:01 localhost CROND[10400]: (user) CMD (/bin/ping 127.0.0.1)
Oct 10 12:42:01 localhost CROND[10417]: (user) CMD (/bin/ping 127.0.0.1)
Oct 10 12:43:01 localhost CROND[10439]: (user) CMD (/bin/ping 127.0.0.1)
Oct 10 12:44:01 localhost CROND[10452]: (user) CMD (/bin/ping 127.0.0.1)

Last edited by khandu; 10-09-2012 at 08:45 PM.
 
Old 10-09-2012, 09:28 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Hmm. Looks OK to me. Let's see. Could you move the ".forward" to say "backup_.forward" and replace the '/bin/ping 127.0.0.1' with something like '/bin/true|mail -s "Hello World" user@machine' and then check user@machines mail and check your mailer daemons logs?
 
Old 10-09-2012, 09:35 PM   #9
khandu
Member
 
Registered: Sep 2003
Posts: 79

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by unSpawn View Post
Hmm. Looks OK to me. Let's see. Could you move the ".forward" to say "backup_.forward" and replace the '/bin/ping 127.0.0.1' with something like '/bin/true|mail -s "Hello World" user@machine' and then check user@machines mail and check your mailer daemons logs?
crontab -l

Quote:
* * * * * '/bin/mail -s "Hello World" XXXXX@XXX'

/var/log/maillog

Quote:
Oct 10 13:33:02 localhost postfix/sendmail[11363]: warning: the Postfix sendmail command has set-uid root file permissions
Oct 10 13:33:02 localhost postfix/sendmail[11363]: warning: or the command is run from a set-uid root process
Oct 10 13:33:02 localhost postfix/sendmail[11363]: warning: the Postfix sendmail command must be installed without set-uid root file permissions
Oct 10 13:33:02 localhost postfix/pickup[11143]: 1D10B2C466: uid=500 from=<root>
Oct 10 13:33:02 localhost postfix/cleanup[11302]: 1D10B2C466: message-id=<20121010023302.1D10B2C466@XXXXXXXX>
Oct 10 13:33:02 localhost postfix/qmgr[2455]: 1D10B2C466: from=<root@XXXXXXX>, size=686, nrcpt=1 (queue active)
Oct 10 13:33:02 localhost postfix/local[11304]: 1D10B2C466: to=<XXXXXXXX>, orig_to=<user>, relay=local, delay=0.06, delays=0.05/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Oct 10 13:33:02 localhost postfix/qmgr[2455]: 1D10B2C466: removed
mail command is showing emails every minute for the user

AND in this scenario.. .forward works..

why is it not working for ping ?? or other scripts??

Last edited by khandu; 10-09-2012 at 09:39 PM.
 
Old 10-10-2012, 07:58 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
Quote:
Originally Posted by khandu View Post
why is it not working for ping ?? or other scripts??
I don't know but at least you now have a workaround and can send email with the 'mail' command from the cron job itself. Should you ever find out why I'd appreciate it if you post about the real cause here.
 
  


Reply

Tags
crontab, email, forward, rhel 6.3, successful


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
[SOLVED] What is the default email (MTA) for RHEL6 vwtech Linux - Software 3 01-17-2011 01:26 PM
crontab email reminder jdwalk Linux - Newbie 3 03-04-2010 04:51 AM
Why can't I send an email after a success install of SuSe Cougar101 Linux - Newbie 3 05-10-2008 11:39 PM
Email & Homepage success! Dolly76 LinuxQuestions.org Member Success Stories 1 12-20-2004 08:36 AM
command-line email success darthtux LinuxQuestions.org Member Success Stories 4 08-31-2003 11:57 PM


All times are GMT -5. The time now is 03:16 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration