Crontab 2>&1 not emailing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab 2>&1 not emailing
# 1  
Old 11-17-2015
Crontab 2>&1 not emailing

I have a script that emails me when I run it manually, but the crontab I'm using must be 'silencing' the output? Here's what I have:

Code:
*/15 * * * * /usr/src/blah.sh > /dev/null 2>&1

I don't want it to email me every time it runs, just when I run the sendmail command inside the script if the conditions in an 'if' statements are true.
# 2  
Old 11-17-2015
First thing I notice is that you are redirecting the output of a script to /dev/null in crontab which does not make much sense to me.
Second, it is a bit difficult to guess what is your script doing without knowing anything it does inside.
Is the same user executing the crontab and the same user that executes the script manually?
# 3  
Old 11-17-2015
What you have is correct. It will redirect any STDOUT and STDERR to the null basket. To restrict cron from emailing add to the cronjob MAILTO="" to disable emailing.

Code:
MAILTO=""
*/15 * * * * /usr/src/blah.sh > /dev/null 2>&1

# Add another MAILTO="some_email_here" for the rest of the jobs
MAILTO="email@me"
* * * * * /path/to/another/script

# 4  
Old 11-17-2015
I see what he means. I got confused with emailing inside the script and emailing outside the script. Thanks Aia.
# 5  
Old 11-17-2015
Every 15 minutes my script does:
Code:
get a temp variable from a sensor

if temp variable > blah; then
          send me a warning email about temp
fi

otherwise just log the temp to a mysql db

So most of the time I don't want an email every 15 minutes that the script ran and logged to the db, just if the temp is high.
# 6  
Old 11-17-2015
The usual problem, your script depends on environment that cron doesn't provide.
To simulate cron, run it with minimal environment in the shell
Code:
env -i PATH=/bin:/usr/bin  /usr/src/blah.sh

# 7  
Old 11-17-2015
Quote:
Originally Posted by unclecameron
Every 15 minutes my script does:
Code:
get a temp variable from a sensor

if temp variable > blah; then
          send me a warning email about temp
fi

otherwise just log the temp to a mysql db

So most of the time I don't want an email every 15 minutes that the script ran and logged to the db, just if the temp is high.
Sorry, but that's no script. That is a plan after which to write a script, at best. Most probably your script bears Cron Problem Number One, but that is just a wild guess as long as you post rubbish instead of your failing script.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help on conditional emailing

Hi All, The following databse table maintains VENDOR and EMAIL details. VENOR_NAME VENDOR_EMAIL DELL surendra@dell.com HP rajkamal@hp.com ACER sumathi@acer.com NOKIA kunal@nokia.com SONY sinu@sony.com We have to find emaild id of a vendor based... (7 Replies)
Discussion started by: ROCK_PLSQL
7 Replies

2. UNIX for Dummies Questions & Answers

Permission on crontab & mysql

HI, I am using centos 6 and finding difficultly in doing 2 below things. 1. i have a user praveen i want to allow him to create cron job of his own. so i have added his user id in cron.allow but still it is not allowing him to edit(even if i have created praveen from root user) or create his... (4 Replies)
Discussion started by: praveenkumar198
4 Replies

3. Solaris

Solaris Crontab & TOP output

Hello Guru's I'm trying to take the output of solaris top command and output to a txt file every few minutes. The issue that I'm experiencing is that I can run the following: #!/bin/bash # logfile="/usr/mvf/morris/top.log" # echo... (2 Replies)
Discussion started by: littlemorris
2 Replies

4. UNIX for Dummies Questions & Answers

What is the purpose of 2 >&1 in crontab?

while we editing the cron at the end of the cron what is the purpose of giving 2 >&1 (4 Replies)
Discussion started by: senmak
4 Replies

5. Fedora

Crontab & MAILTO

Hi there, I'm working with two servers, one with FEDORA 6 and the other one with FEDORA 7, and if I put these lines in crontab: MAILTO=MYADDRESS@mail.com */1 * * * * df -h everything works fine on FEDORA 7 , while it doesn't work on6?!?...and I find this message in the log file: MAIL... (2 Replies)
Discussion started by: Giordano Bruno
2 Replies

6. UNIX for Dummies Questions & Answers

crontab & var/spool/mai

Hi there, I'm using crontab to move some files every minute, but when crontab doesn't find these files it sends a message to the file "user_name" in the directory "var/spool/mail". Is it possible to "bypass" this problem? Thanks in advance, Giordano Bruno (1 Reply)
Discussion started by: Giordano Bruno
1 Replies

7. Shell Programming and Scripting

emailing as body of email

hi all, how do i email a file in the body of an email rather than as an attachment ?? have a ksh script which i need to read a file and email as part of the body rather than an attachment. my code is : uuencode file.log | mailx -s "test" but this sends file as an attachment. ... (2 Replies)
Discussion started by: cesarNZ
2 Replies

8. Shell Programming and Scripting

script not emailing or running

Hi, I am having trouble with this script. It is suppose to send me an email when the specified tablespace is 60% full. I run it but nothing happens FREESPACELOG=/home/oracle/scripts/bin/free_space/freespace.sql email=bob@bob.edu subject="PROD: Tablespace Free Space" cmd="mailx -s... (1 Reply)
Discussion started by: shaseeb
1 Replies

9. UNIX for Dummies Questions & Answers

Monitoring & emailing log files

Hi ..first post ! I have a Unix v445 using solaris 10. I've trolled through various web pages but can't find exactly what I'm looking for. I have an alert log...or any messages file for that matter I need to check for certain key (error type) phrases - if I find them, they are redirected to... (11 Replies)
Discussion started by: davidra
11 Replies

10. Solaris

ssh & crontab bug

Does any one knows a work around for the crontab bug when connecting using ssh to a Solaris 8 system? When you submit a crontab job through a ssh session, the job will not be executed, SunSolve has reported no fixing patches? (3 Replies)
Discussion started by: Negm
3 Replies
Login or Register to Ask a Question