LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-22-2017, 07:05 AM   #1
postcd
Member
 
Registered: Oct 2013
Posts: 527

Rep: Reputation: Disabled
Ways to prevent cron e-mails from particular bash script located in cron.daily?


Hello,

i have a bash script in /etc/cron.daily/myscript

and receiving e-mails each time this script run:
Quote:
From: Anacron <root@myserver>
To: root@myserver
Content-Type: text/plain; charset="ANSI_X3.4-1968"
Subject: Anacron job 'cron.daily' on myserver
Status: R
I do not want to receive e-mails for this particular bash script.

I know i can edit bash script and output commands output STDERR/OUT to /dev/null but there is too many lines.

How can i mute these e-mails for this particular bash script or mute that bash script STDOUT/ERR please ?

I know i can create new file in /etc/cron.d and inside it add something like:
15 0 * * * root /bin/sh /etc/cron.daily/myscript >/dev/null 2>&1

But i want the bash script to stay in cron.daily, any way to do so in a simple way?

crontabs-1.10-33

Last edited by postcd; 08-22-2017 at 07:07 AM.
 
Old 08-22-2017, 07:19 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by postcd View Post
Hello,
i have a bash script in /etc/cron.daily/myscript and receiving e-mails each time this script run:
Code:
From: Anacron <root@myserver>
To: root@myserver
Content-Type: text/plain; charset="ANSI_X3.4-1968"
Subject: Anacron job 'cron.daily' on myserver
Status: R
I do not want to receive e-mails for this particular bash script. I know i can edit bash script and output commands output STDERR/OUT to /dev/null but there is too many lines.

How can i mute these e-mails for this particular bash script or mute that bash script STDOUT/ERR please ?

I know i can create new file in /etc/cron.d and inside it add something like:
15 0 * * * root /bin/sh /etc/cron.daily/myscript >/dev/null 2>&1

But i want the bash script to stay in cron.daily, any way to do so in a simple way?

crontabs-1.10-33
Try looking at the answers in your OTHER thread about a very similar issue:
http://www.linuxquestions.org/questi...5/#post5730486

And the statement "I know i can edit bash script and output commands output STDERR/OUT to /dev/null but there is too many lines." doesn't lend credence to you having done much (if any) research on your own, as stated in the "Question Guidelines", as you've been pointed to MANY times. How many lines are in this script? And doing a global search/replace is trivial, to get statements at the end of every line...even a simple sed could do it with one line, so it's hard to believe that it's so hard, or that a cron script would have many lines at all.

Again, your last thread about this has the solution...in the post you were handed, along with the links IN that post. Here's a hint: instead of setting MAILTO to an address.....TRY SETTING IT TO NOTHING.
 
Old 08-22-2017, 08:55 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
At the top of the script (well, after the "#!" line), just insert the lines
Code:
exec >/dev/null
exec 2>/dev/null
That will re-define stdout and stderr for the rest of the script. If the unwanted output is just from stdout, it's probably best to leave stderr alone so that you'll still get messages if something goes wrong. It's really annoying when things fail silently.
 
4 members found this post helpful.
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where are cron jobs located when not under /var/spool/cron/root? NotionCommotion Linux - Newbie 6 09-07-2012 07:33 AM
[SOLVED] /etc/cron.daily/slocate.cron - multiple /usr/bin/updatedb degrades performance ray63 Linux - Server 2 01-05-2012 05:04 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM
cron.daily mails fatal error message in fedora core 2 jordanthompson Linux - Software 4 12-22-2004 07:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:10 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration