DaemonForums  

Go Back   DaemonForums > Miscellaneous > General software and network

General software and network General OS-independent software and network questions, X11, MTA, routing, etc.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 12th May 2022
dchmelik's Avatar
dchmelik dchmelik is offline
Real Name: David Chmelik
Port Guard
 
Join Date: Oct 2017
Location: USA
Posts: 38
Question multiple-command cron jobs without emails?

I do many cron jobs like below.
Code:
0 0 * * * command1 && command2 && command3 && command4 && command5 1> /dev/null 2>&1
Obviously I don't want their emails but apparently first four email, I guess not fifth. Is there a way to stop emails other than '1> /dev/null 2>&1' at end of every command?
        I'd like to know for *BSD Unix (Open, Free, and fine to describe Net, DragonFly, IllumOS) and hopefully strictly Unix-like GNU/Linux (Slackware, though I don't use Devuan or Gentoo much., and don't consider latter two strictly Unix-like but almost, and no others well-known are anything close.)
__________________
David
homesite mirror (most uptime) / homesite (updated first)

Last edited by dchmelik; 12th May 2022 at 11:24 AM.
Reply With Quote
  #2   (View Single Post)  
Old 12th May 2022
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

I'd put all of those commands you've strung together into a script, and execute the script.

OpenBSD's cron(8) man page says:
Quote:
Any output produced by a command is sent to the user specified in the MAILTO environment variable as set in the crontab(5) file or, if no MAILTO variable is set (or if this is an at(1) or batch(1) job), to the job's owner. If a command produces no output or if the MAILTO environment variable is set to the empty string, no mail will be sent. The exception to this is at(1) or batch(1) jobs submitted with the -m flag. In this case, mail will be sent even if the job produces no output.
Reply With Quote
  #3   (View Single Post)  
Old 14th May 2022
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

One thing to remember is that the MAILTO variable will be used in all subsequent cron jobs

Code:
MAILTO=""
0 0 * * * command1 && command2 && command3 && command4 && command5 
1 1 * * * command1 && command2 && command3
MAILTO=root
2 2 * * * command1 && command2
In this example the first two jobs will not produce any emails. In order to get an email for the third job, you will have to set MAILTO again.
To prevent this I find it easier is to move all the no-email-wanted jobs to the end:
Code:
MAILTO=root
2 2 * * * command1 && command2
MAILTO=""
0 0 * * * command1 && command2 && command3 && command4 && command5 
1 1 * * * command1 && command2 && command3
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Reply

Thread Tools
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scheduling jobs with at(1) instead of cron(8) J65nko Guides 0 13th May 2021 06:01 AM
Can't send emails with msmtp - domain name conflict acampbell OpenBSD General 5 14th January 2015 06:51 PM
Why Bad Jobs (or No Jobs) Happen To Good Workers ocicat News 3 22nd June 2012 04:56 PM
Parsing emails with 'awk' and 'perl' J65nko Guides 1 24th February 2011 03:34 AM


All times are GMT. The time now is 10:40 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick