Cron Email Error Only
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
Cron Mail Only On Error
Learn more about Stack Overflow the company Business Learn more about hiring developers cron send email on error or posting ads with us Server Fault Questions Tags Users Badges Unanswered Ask Question _ Server Fault is a question and
Cron Error Failed To Open Pam Security Session Success
answer site for system and network administrators. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted cron error bad minute up and rise to the top Cron: Only get errors in emails? up vote 22 down vote favorite 5 I finally set up a realistic backup schedule on my data through a shell script, which are handled by cron on tight intervals. Unfortunately, I keep getting empty emails each time the CRON has been executed and not only when things go wrong. Is it possible to only make cron error can't switch user context CRON send emails when something goes wrong, ie. my TAR doesn't execute as intended? Here's how my crontab is setup for the moment; 0 */2 * * * /bin/backup.sh 2>&1 | mail -s "Backup status" email@example.com Thanks a lot! bash shell cron schedule share|improve this question asked Jan 24 '11 at 9:40 Industrial 53921535 add a comment| 4 Answers 4 active oldest votes up vote 32 down vote accepted Ideally you'd want your backup script to output nothing if everything goes as expected and only produce output when something goes wrong. Then use the MAILTO environment variable to send any output generated by your script to your email address. MAILTO=email@example.com 0 */2 * * * /bin/backup.sh If your script normally produces output but you don't care about it in cron, just sent it to /dev/null and it'll email you only when something is written to stderr. MAILTO=email@example.com 0 */2 * * * /bin/backup.sh > /dev/null share|improve this answer answered Jan 24 '11 at 9:53 Cakemox 13.1k52957 add a comment| up vote 8 down vote Using cronic wrapper script looks like a good idea; to use it you don't have to change your scripts. Instead of: 0 1 * * * backup >/dev
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
Cron Error Cannot Set Security Context
email output only when error occurs in CentOS 6.3, I have "/sbin/service cron error can't fork iptables save" in cron. How do I set cron to only email when there is an error
Cron Error Bad Username
or, if possible, run "service" silently (unless there is an error)? If none of these options are possible, is running "iptables-save > /etc/sysconfig/iptables" instead the only remaining choice? http://serverfault.com/questions/226074/cron-only-get-errors-in-emails Thanks Log in or register to post comments #2 Tue, 08/14/2012 - 11:04 andreychek Howdy, Cron will 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... https://www.virtualmin.com/node/23080 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 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)
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies http://unix.stackexchange.com/questions/225219/cron-only-occasionally-sends-e-mail-on-output-and-errors of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Unix & Linux Questions Tags Users Badges Unanswered Ask https://scottlinux.com/2010/12/13/cron-only-email-errors/ Question _ Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute: Sign on error 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 Cron only occasionally sends e-mail on output and errors up vote 2 down vote favorite On Debian 8.1, I'm using a Bash feature to detect whether the stackoverflow.com website is reachable: (echo >/dev/tcp/stackoverflow.com/80) &>/dev/null || echo "stackoverflow unreachable" This is cron error bad Bash-specific and will not work in sh, the default shell of cron. If we, on purpose, try the script in sh, we get: $ /bin/sh: 1: cannot create /dev/tcp/stackoverflow.com/80: Directory nonexistent Hence, if I only put the following in my personal crontab (without setting SHELL to /bin/bash) via crontab -e, I expect that once per minute, the script will be executed, and I therefore expect to also get the above error sent per mail once per minute: * * * * * (echo >/dev/tcp/stackoverflow.com/80) &>/dev/null || echo "stackoverflow unreachable" And indeed, exactly as expected, we see from /var/log/syslog that the entry is executed once per minute: # sudo grep stackoverflow /var/log/syslog Aug 24 18:58:01 localhost CRON[13719]: (mat) CMD ((echo >/dev/tcp/stackoverflow.com/80) &>/dev/null || echo "stackoverflow unreachable") Aug 24 18:59:01 localhost CRON[13723]: (mat) CMD ((echo >/dev/tcp/stackoverflow.com/80) &>/dev/null || echo "stackoverflow unreachable") Aug 24 19:00:01 localhost CRON[13727]: (mat) CMD ((echo >/dev/tcp/stackoverflow.com/80) &>/dev/null || echo "stackoverflow unreachable") ... During the last ~2 hours, this was executed more than 120 times already, as I can verify with piping the output to wc -l. However, from these >120 times the shell command (to repeat: the sh
Example: */30 * * * * /usr/local/bin/myscript.pl >/dev/null
Optional more geeky details: There are two different kinds of output from any given command. ">" is the same as issuing "1>" which is the non-error output. This is being sent to /dev/null in the above example. "2>" is the "error" output. Leaving this out of your crontab entry as above means it is processed as normal (2> output is emailed to you). Category: linux sysadmin Tags: bash, cron, cron job, crontab, email, errors, ubuntu server Post navigation ← Install Ubuntu Linux on Chrome Cr-48 shellinabox With Apache Authentication Over HTTPS 443 → Leave a Reply Cancel reply Your email address will not be published. Required fields are marked *Comment Name * Email * Website Notify me of followup comments via e-mail. You can also subscribe without commenting. Please note: JavaScript is required to post comments. Search for: Subscribe to scottlinux.com | Linux Blog Your email: Leave Blank: Don't Change: IPv6 detectorDarn. Looks like you are still using IPv4. 192.3.173.230 Show stats Hide stats This server has received 3489332 hits from both ipv4 and ipv6. IPv496.0% IPv64.0% Recent CommentsBrian on How to Relay Mail from TWC Home ConnectionsDennis on How To Create a systemd Service in Linux (CentOS 7)Jack on OpenVAS 0 byte pdf | Backtrack LinuxClyde W. Stewart on Thunderbird Recover Email PasswordClyde W. Stewart on Thunderbird Recover Email PasswordScott Miller on GPU Passthrough with KVM and Debian Linuxerror 1722 on Ubuntu 11.04 Change From Unity To Classic GnomeTopicsadministration android apache apt-get backup bash browser centos command line database debian dns email firewall hard drive how to https impress your boss iptables ipv6 linux linux desktop mysql network networking nginx nmap openssl os x password php privacy redhat red hat security ssh SSL terminal tls tor ubuntu ubuntu server video web server wordpress Powered by Linode and Debian Linux! Support scottlinux.com | linode | hover | digitalocean | BTC donation 19Bgu5V281B2fbTFUHFcMCBwWLPVnLGNFe Copyleft 2016 scottlinux.com CC BY-SA 3.0 Iconic One Theme | Powere