1846548 Members
2267 Online
110256 Solutions
New Discussion

Re: cron msg

 
SOLVED
Go to solution
Vogra
Regular Advisor

cron msg

Hi All!
i have a cron script that run all minutes from specifc hour, but sometimes the result is not important for me.
Can I disable cron messagem from specific script or all times it runs cron send me a msg?
Thanx.
We are spirits in the material world
7 REPLIES 7
Patrick Wallek
Honored Contributor

Re: cron msg

I'm not quite sure I understand what you are trying to do, but how about something like this:

0-59 8-17 * * 1-5 /dir/script_to_run 2>&1 | mailx -s "Output from script" email@somewhere.com

This will re-direct standard error to standard out and then e-mail you the output once the script finishes.

Be aware that any redirection in the script itself will effect what you receive from this e-mail.
Oleg Zieaev_1
Regular Advisor
Solution

Re: cron msg

Hello.

You will need to redirect output of your program to /dev/null 2>&1:
00 * * * * myprog.sh > /dev/null 2>&1.
If you want to manage some log info - do it within the script/program you run.

Hope this helps.
0leg
Professionals will prevail ...
Kellogg Unix Team
Trusted Contributor

Re: cron msg

If you don't want standard msgs emailed to you, you can do something like -

* HH1-HH2 * * * 1>/dev/null

This way, if everything goes well, the standard output will go to /dev/null. If your script failed for any reason, you will get a msg.

Is that what you want?

...Manjeet
work is fun ! (my manager is standing behind me!!)
Vogra
Regular Advisor

Re: cron msg

Hi!
I want to control what I will receive by script. I don't want cron send msg that my script ran...
We are spirits in the material world
S.K. Chan
Honored Contributor

Re: cron msg

If you look at /usr/sbin/cron executable ..
# strings /usr/sbin/cron|more
almost towards the bottom ..
..
/usr/bin/echo 'Subject: %s
' | /usr/bin/cat - "%s" | %s %s
cron
/usr/bin/mail
...
Meaning cron by default will email root of its stdout and stderr. If you do not want this email, you will have to redirect the stdout/stderr in the crontab file like suggested by the rest.
Mladen Despic
Honored Contributor

Re: cron msg

Just modify the script that's sending you emails. If you want to continue running the script every minute, but you only need a report every hour, then you can replace the relevant mail command. For example if your mail command is:

cat myoutput | mailx -s "my subject" myself@mycompany.com

then replace it with something like this:

if [ `date +%M` = 0 ]
then
cat myoutput | mailx -s "my subject" myself@mycompany.com
fi

The mailx command will then be executed at every full hour.
Mladen Despic
Honored Contributor

Re: cron msg

I might have misunderstood. I thought you were receiving emails internally from the script that's run by cron. But if you are receiving emails from the cron itself, then S.K. Chan's comments are relevant.

Mladen