Cron Email On Error
Contents |
Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn
Cron Email On Error Only
more about hiring developers or posting ads with us Server Fault Questions Tags Users Badges cron error mail Unanswered Ask Question _ Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:
Cron Error Failed To Open Pam Security Session Success
Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top How to get e-mail from (failed) cron-jobs in Ubuntu? up vote 34 down cron error bad minute vote favorite 13 I create cron-jobs in Ubuntu by placing the executable in one of /etc/cron.{daily,hourly,monthly,weekly}. There are lots of directories starting with cron: kent@rat:~$ ls -ld /etc/cron* drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.d drwxr-xr-x 2 root root 4096 2009-07-16 13:17 /etc/cron.daily drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.hourly drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.monthly -rw-r--r-- 1 root root 724 2009-05-16 23:49 /etc/crontab drwxr-xr-x 2 root root 4096 2009-06-06 18:52 /etc/cron.weekly I cron error can't switch user context would like to get e-mail from my scripts when: A script fails and gives an exit code of non-zero. The script has something to tell me I have SSMTP installed and working, I send my mail from my Google-account. The fact that SSMTP can only send mail using one account isn't a problem for me. It's just a home server and the users I have do not have the ability to add cron-jobs. I would like to know how the mailing from scripts usually works in Linux/Unix in general and in Ubuntu specifically. I would also like to know of a good way for me to get mails in the two situations above. linux ubuntu unix cron email share|improve this question asked Aug 14 '09 at 10:01 Deleted 77241430 add a comment| 7 Answers 7 active oldest votes up vote 47 down vote By default, cron will email the owner of the account under which the crontab is running. The system-wide crontab is in /etc/crontab runs under the user `root' Because root is used widely, I'd recommend adding a root alias to your /etc/aliases file anyways. (run 'newaliases' after) The normal way to structure this is for root to be aliased to another user on the system, e.g. for me I'd alias 'root' to 'phil' (my user account) and alias 'phil' to my external email address. If you have
output only when error occurs 7 posts / 0 new Log in or register to post comments Last post #1 Tue, 08/14/2012 - 10:48 eddieb Cron email output only when error occurs in CentOS 6.3,
Cron Error Cannot Set Security Context
I have "/sbin/service iptables save" in cron. How do I set cron to cron error can't fork only email when there is an error or, if possible, run "service" silently (unless there is an error)? If
Cron Error Bad Username
none of these options are possible, is running "iptables-save > /etc/sysconfig/iptables" instead the only remaining choice? Thanks Log in or register to post comments #2 Tue, 08/14/2012 - 11:04 andreychek Howdy, Cron will http://serverfault.com/questions/54152/how-to-get-e-mail-from-failed-cron-jobs-in-ubuntu email you with any output produced by the programs it's running. So the key would be to make sure the program you're running isn't outputting anything unless it's an error. You can accomplish that by redirecting the standard output... something like this: /sbin/service iptables save >/dev/null With that, all normal output will be redirected to /dev/null, but warning/error output will still be generated (and thus https://www.virtualmin.com/node/23080 emailed). -Eric Log in or register to post comments #3 Tue, 08/14/2012 - 11:31 (Reply to #2) eddieb for future reference, I think you meant >/dev/null 2>&1 thanks! Log in or register to post comments #4 Tue, 08/14/2012 - 12:05 andreychek Howdy, Well, the forum mangled what I typed, but I meant just: >/dev/null What you mentioned there, " >/dev/null 2>&1", will cause all output, both regular and errors, to go to /dev/null... and it didn't sound like that's what you wanted. By using just ">/dev/null", only standard output is redirected to /dev/null, and errors will still be output, which will cause them to be emailed to you. -Eric Log in or register to post comments #5 Tue, 08/14/2012 - 12:13 (Reply to #4) eddieb correct, thanks! Log in or register to post comments #6 Thu, 05/15/2014 - 23:48 (Reply to #5) davehprohoods This doesn't work for me on CentOS 6.3 and 6.4; not sure why. Please let me know if you did anything additional to get it to work. Log in or register to post comments #7 Wed, 08/15/2012 - 06:44 Locutus Please note though that this method of course only
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or http://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to save cronjob error to file and email it? up vote 2 down vote favorite 1 my goal is to save cronjob error and email it to me. I don't care about standard output, that's on error why I redirect it to /dev/null. Sending mail is done by this setting in crontab: MAILTO=my@email.com I tried to run it with following command: * * * * * /path/to/script.sh > /dev/null 2 >> /path/to/file.log It emails the error all right. The log file is created but is empty. What am I doing wrong? ================================================================================== I found the solution. Thank you all for your help! (I cannot post it as an answer, so I am amending the solution here.) I used cron email on this reference How can I redirect stderr to a pipe? # version 2: redirect stderr to the pipe without getting stdout (it's # redirected to /dev/null) myprog 2>&1 >/dev/null | grep ... My solution is: #crontab MAILTO=my@email.com * * * * * /path/to/script.sh 2>&1 >/dev/null | tee -a /path/to/file.log Explanation: redirecting stderr to the pipe without getting stdout and then using tee -a for appending the stderr to the log file and printing it to the terminal, which is redirected automatically to email (see MAILTO). So I have a log file and email both containing the error message. linux crontab share|improve this question edited Oct 18 '13 at 18:12 asked Oct 18 '13 at 14:05 Petr 467 crontab needs the full path of the scripts to be executed. Try with * * * * * /bin/sh /path/to/script.sh ... –fedorqui Oct 18 '13 at 14:08 Does your script actually send anything to stderr? –user1864610 Oct 18 '13 at 14:08 @fedorqui it's not a problem of the path, the file is created all right –Petr Oct 18 '13 at 14:13 @MikeW yes, I get the error message in email –Petr Oct 18 '13 at 14:14 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted My solution is: #crontab MAILTO=my@email.com * * * * * /path/to/script.sh 2>&1 >/dev/null | tee -a /path/to/file.log Explanation see above in my first post. share|improv