LinuxQuestions.org
Register a domain and help support LQ
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 11-16-2007, 09:50 AM   #1
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Rep: Reputation: 30
help: using cron + my bash script --> don't want mail from script


good morning folks,

I wrote a bash script which logs into our database and generates a neato report telling me a daily breakdown of transactions per device. I launch it every morning automagically using cron (crontab -e .... enter all the parameters....). That part works just lovely.

The report output is sent to an output file (daily_report_${inputdate}.txt). The database connection/disconnection messages are all sent to my user's mail account.

Is there a way that I can NOT have any of those boring old messages sent to my mail account cause I'd rather not have to clean up garbage mail...?

thanks.

 
Old 11-16-2007, 09:53 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,378

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
sure, just redirect the script output to /dev/null...

* */5 * * * /bin/myscript 2>&1 /dev/null
 
Old 11-16-2007, 09:54 AM   #3
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
You should define an empty MAILTO variable at the beginning of the crontab:
Code:
MAILTO=""
 
Old 11-16-2007, 11:15 AM   #4
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Original Poster
Rep: Reputation: 30
thanks for the good feedback.

I'm curious if "...myscript 2>&1 >/dev/null" would interfere with my actual report. Inside the functions I take that line of output and redirect it to my output file: >> $outfile. Would sending sterr + stout to the great void also take my report into |-|3||? I'll test it here shortly and report.

I also like the MAILTO="" idea.

Currently my crontab looks like this:
33 09 * * * bash /home/myuser/number_trans_daily

Does this look right?
MAILTO=""
...(other entries)...
33 09 * * * bash /home/myuser/number_trans_daily

Last edited by beeblequix; 11-23-2007 at 09:07 AM.
 
Old 11-16-2007, 11:43 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,378

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
it won't interfere, no. it's only what comes out to the console, which is what cron is sending you.

i wouldn't recommend changing MAILTO personally, as it's only *THIS* script you want to silent, not everything in cron.
 
Old 11-16-2007, 12:18 PM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Quote:
Originally Posted by acid_kewpie View Post
i wouldn't recommend changing MAILTO personally, as it's only *THIS* script you want to silent, not everything in cron.
I agree. Sorry but I did not think about other crontab entries, I was just focused on the single one. Indeed, redirection of stdout and stderr to /dev/null is far better. Thanks for taking notice!
 
Old 11-23-2007, 09:09 AM   #7
beeblequix
Member
 
Registered: Oct 2005
Location: Tierra Firma, Earth
Distribution: Debian of course...
Posts: 196

Original Poster
Rep: Reputation: 30
I added "2>&1 >/dev/null" to the end of a few of my entries in the crontab and it's now working just as intended. Thanks for your help.

 
Old 11-23-2007, 09:25 PM   #8
mRgOBLIN
Slackware Contributor
 
Registered: Jun 2002
Location: New Zealand
Distribution: Slackware
Posts: 999

Rep: Reputation: 226Reputation: 226Reputation: 226
A better idea might be just to redirect std_out to /dev/null and leave std_err alone. This way you will only get mail if some error occurs in your cronjob.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Run bash commands script as cron anjanesh Linux - General 4 04-03-2007 06:25 AM
Bash script and cron job rust8y Linux - General 2 07-08-2006 07:45 AM
bash script causes trouble with cron Suinatsa Programming 10 06-14-2006 03:20 AM
cron bash script troubles zzyzx Slackware 3 04-12-2005 12:27 PM
bash script from cron kubla Programming 3 01-22-2004 04:30 AM


All times are GMT -5. The time now is 07:52 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration