PDA

View Full Version : [ubuntu] Cron job issues



m3bik
May 6th, 2009, 07:19 AM
I have a cronjob that executes a local php script. I currently have it set to:


wget -O http://localhost/script.php

There is no actual output from the script. Nothing is downloaded or saved to my server. I do, however, get emails sent to my user account letting me know the cronjob was successful.

How can I do this cronjob with now email, no output, nothing... I've tried adding


> /dev/null &> /dev/null

to the end of the command, but I still get an email sent to the user account.

Is there an easier way to do this cronjob that does NOT send emails?

I ask this because this cronjob is done every 5 minutes and that can be a lot of emails after a few days! I know I could set a cronjob to erase the email file at /var/mail/user but then it would send another email saying that cronjob was successful...

nquinnathome1
May 6th, 2009, 01:21 PM
Just to be sure; have you tried running the script in a browser or calling it with PHP CGI (if you have that installed)?

You should call it like:

wget -O /dev/null http://localhost/script.php

Adding /dev/null sends the output to a null device so the file isn't saved to disk.

Also, regarding your cronjob mails; you don't have to have an email sent when you run a job; you could always set a job that doesn't mail you when it deletes the mails.

m3bik
May 6th, 2009, 09:56 PM
I just want to run the php script every 5 minutes, not save anything to the server, and NOT get an email sent to the user account after the cronjob. How ever I have to do that is how I'll do that...

I've tried


wget -O /dev/null http://localhost/script.php


wget -O /dev/null http://localhost/script.php > /dev/null &> /dev/null


wget http://localhost/script.php > /dev/null &> /dev/null

I've even tried lynx instead of wget.

I'm not even sure if each one is completely correct, it's just that I'll do anything for no more emails after a cronjob!

Here's an example of what the emails look like:


From user@ubuntu.inet Wed May 6 16:00:02 2009
Return-Path: <user@ubuntu.inet>
X-Original-To: user
Delivered-To: user@ubuntu.inet
Received: by ubuntu (Postfix, from userid 1000)
id 5226E849D; Wed, 6 May 2009 16:00:02 -0500 (CDT)
From: root@ubuntu.inet (Cron Daemon)
To: user@ubuntu.inet
Subject: Cron <user@ubuntu> wget -O /dev/null http://localhost/cron.php > /dev/null &> /dev/null
Content-Type: text/plain; charset=UTF-8
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/user>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=user>
Message-Id: <20090506210002.5226E849D@ubuntu>
Date: Wed, 6 May 2009 16:00:02 -0500 (CDT)

--2009-05-06 16:00:02-- http://localhost/cron.php
Resolving localhost... 192.168.2.124
Connecting to localhost|192.168.2.124|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 0 [text/html]
Saving to: `/dev/null'

0K 0.00 =0s

2009-05-06 16:00:02 (0.00 B/s) - `/dev/null' saved [0/0]

John Cheng
May 7th, 2009, 02:09 AM
I just want to run the php script every 5 minutes, not save anything to the server, and NOT get an email sent to the user account after the cronjob. How ever I have to do that is how I'll do that...

I've tried







I've even tried lynx instead of wget.

I'm not even sure if each one is completely correct, it's just that I'll do anything for no more emails after a cronjob!

Here's an example of what the emails look like:

Yikes, did you accidentally overwrite your /dev/null as a file?

What is the output of "stat /dev/null", it should look like



stat /dev/null
File: `/dev/null'
Size: 0 Blocks: 0 IO Block: 4096 character special file
Device: fh/15d Inode: 3298 Links: 1 Device type: 1,3
Access: (0666/crw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2009-05-05 21:04:45.000000000 -0700
Modify: 2009-05-05 21:04:45.000000000 -0700
Change: 2009-05-06 06:03:11.465959640 -0700


If it has become a real file (instead of a character device), then you can delete it. Once deleted, recreate it with



mknod -m 666 /dev/null c 1 3


In your cron job listing, you should not use the -O option, in other words:


wget -O /dev/null http://localhost/cron.php > /dev/null &> /dev/null

Simply the following will be fine:


1 2 3 4 * wget http://localhost/cron.php &> /dev/null

m3bik
May 7th, 2009, 06:30 AM
This is my outcome for:

stat /dev/null


File: `/dev/null'
Size: 0 Blocks: 0 IO Block: 4096 character special file
Device: eh/14d Inode: 5152 Links: 1 Device type: 1,3
Access: (0666/crw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2009-04-27 16:37:20.000000000 -0500
Modify: 2009-04-27 16:37:20.000000000 -0500
Change: 2009-05-05 22:25:19.752173230 -0500


It looks right to me.

m3bik
May 7th, 2009, 10:04 AM
/dev/null looks right and I've used


wget http://localhost/cron.php &> /dev/null

and I still get emails...

m3bik
May 7th, 2009, 08:22 PM
Is this just impossible to do?

gombadi
May 7th, 2009, 09:55 PM
according to the man page for wget there is a quiet option.



-q
--quiet
Turn off Wgetís output.


Have you tried it?

SciFi-Bob
May 7th, 2009, 10:00 PM
One option is to disable all logging from cron, like this:

Alter the last line in /etc/default/cron to this:

EXTRA_OPTS="-L 0"

This will disable audit logging of all cron events.
I don't know if this will affect the mails, but it's certainly stopping the syslog from being filled up with cron lines.

Anyway, try a "man cron" for options to the cron daemon.