LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Red Hat (http://www.linuxquestions.org/questions/red-hat-31/)
-   -   Get email from crontab on success RHEL6 (http://www.linuxquestions.org/questions/red-hat-31/get-email-from-crontab-on-success-rhel6-4175431396/)

khandu 10-09-2012 06:37 PM

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..

unSpawn 10-09-2012 07:12 PM

Quote:

Originally Posted by khandu (Post 4801666)
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.

khandu 10-09-2012 07:18 PM

Quote:

Originally Posted by unSpawn (Post 4801676)
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

unSpawn 10-09-2012 07:34 PM

Quote:

Originally Posted by khandu (Post 4801679)
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.

khandu 10-09-2012 07:35 PM

Quote:

Originally Posted by unSpawn (Post 4801684)
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

unSpawn 10-09-2012 08:23 PM

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?

khandu 10-09-2012 08:43 PM

Quote:

Originally Posted by unSpawn (Post 4801714)
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)

unSpawn 10-09-2012 09:28 PM

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?

khandu 10-09-2012 09:35 PM

Quote:

Originally Posted by unSpawn (Post 4801745)
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??

unSpawn 10-10-2012 07:58 AM

Quote:

Originally Posted by khandu (Post 4801753)
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.


All times are GMT -5. The time now is 12:54 PM.