Cron Log email sending non-stop

erictham

Verified User
Joined
Oct 17, 2004
Messages
26
I have setup some cron jobs to be run , whenever this crons is run, i will recive an email on the cron daemon, now i have 100's over mail sending to me every min. How can i stop the cron from sending me logs everytime a cron is run?


This is the message i receive:

Return-path: <[email protected]>
Envelope-to: [email protected]
Delivery-date: Fri, 19 Nov 2004 12:59:00 +0800
Received: from icentel by server.icentel.com with local (Exim 4.42)
id 1CV0rM-0005lu-JE
for [email protected]; Fri, 19 Nov 2004 12:59:00 +0800
From: [email protected] (Cron Daemon)
To: [email protected]
Subject: Cron <icentel@server> /home/icentel/domains/icentel.com/cron/cron_jobrun.sh www.icentel.com lasttopupsuspend
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/icentel>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=icentel>
Message-Id: <[email protected]>
Sender: CronDaemon <[email protected]>
Date: Fri, 19 Nov 2004 12:59:00 +0800
 
Since you don't tell us anything about the cron job it's hard to tell you.

Are you getting job output emailed to you or something else?

If it's job output the way to keep it from getting mailed to you is to make sure there's no output.

For most programs called in a crontab you can do that by calling the program with this at the tail end of the command:

> /dev/null 2>&1

Jeff
 
Hi,

I really don't quite understand what you meant, can you define in more details? I believe i am receiving mails whenever the cron is run. How can i really disable that?


Here's the php file:

<?php
include "./includes/sp_config.php";

$query = 'select commissions.personalid,members.sponsorid,(sum(credit)-sum(debit)) as total,(sum(credit)-sum(debit))*(signup_subtype.match_bonus/100) AS bonus from commissions JOIN members USING (personalid) JOIN member_properties ON (members.sponsorid=member_properties.personalid) JOIN signup_subtype ON (member_properties.propertyvalue=signup_subtype.id) WHERE commissions.status=\'hold_'.$hold_number.'\' AND member_properties.propertyname=\'signup_subtype\' GROUP BY commissions.personalid HAVING (sum(credit)-sum(debit))>0';
$db->setquery($query);
$bonuses = $db->select();
if(count($bonuses)!=0) {
foreach($bonuses as $bonus) {
$commission = new commissions($bonus['sponsorid'], $bonus['bonus'], 'Match Bonus from ' . $bonus['personalid'], 0, FALSE);
$commission->SetAccount('balance');
$commission->AddCommission($bonus['bonus']);

}
}

$query = 'select commissions.personalid,(sum(credit)-sum(debit)) as total from commissions JOIN members USING (personalid) WHERE commissions.status=\'hold_'.$hold_number.'\' GROUP BY commissions.personalid HAVING (sum(credit)-sum(debit))>0';
$db->setquery($query);
$transfers = $db->select();
if(count($transfers)!=0) {
foreach($transfers as $transfer) {
$query = 'UPDATE member_balance SET balance=balance+'.$transfer['total'].',pending=pending-'.$transfer['total'].' WHERE personalid='.$transfer['personalid'];
$db->setquery($query);
$db->sql();
}
}

$query = 'UPDATE commissions SET status=\'balance\' WHERE status=\'hold_'.$hold_number.'\'';
$db->setquery($query);
$db->sql();

$db->disconnect();
?>
 
I can't take the time to debug your php right now; perhaps someone else can.

If you don't need the email you can probably eliminate it the way I explained.

If you put the php file directly into (for example) cron.daily or cron.hourly, you'll have to rewrite it, but what you should do is put a small script into the cron directory to run the php file.

For example, if the php file is in your /usr/local directory and is named file.php, you can call it with a short shell script in (for example) cron.daily:
Code:
#!/bin/sh
/usr/local/file.php > /dev/null 2>&1

Jeff
 
Do what Jeff says and that will eliminate the emails. Cron will email the admin for any job that produces any output. The redirect '> /dev/null 2>&1' is what prevents the emails. The '> /dev/null' tells the job to send all stdout to /dev/null and the '2>&1' part tells the job to send all stderr to the same place as stdout, in this case /dev/null.
 
Hi do i get you right that i should add the /dev/null 2>&1 in my php codes or the command line i execute this code.

Right now my cron job in direct admin is schdule to run this:

* 12,23 * * * /home/icentel/domains/icentel.com/cron/cron_jobrun.sh www.icentel.com lasttopupsuspend

This is the codes in cron_jobrun.sh
#!/bin/bash
lynx -dump http://$1/sys/cron_$2.php?domain=${1:4}


I think i need to know where to put this /dev/null 2>&1 ?
 
Your cron entry should look like:
Code:
* 12,23 * * * /home/icentel/domains/icentel.com/cron/cron_jobrun.sh [url]www.icentel.com[/url] lasttopupsuspend > /dev/null 2>&1
 
Back
Top