NVG
NVG

Reputation: 3333

cronjobs not working

For the past few hours I am struggling to make my cronJobs work. Believe me I googled everything and I even searched on stackoverflow but somehow the code I saw didnt work as expected. This is why I posted here.

I am doing this in SSH :

crontab -e

Then I edit my cronjob list and I add this :

[email protected]
*   *   *   *   *   wget -q "http://www.mywebsite.com/path/to/cronJob.php"

I get no response on my email with the PHP response. PHP has an output if I call it from browser but I dont get anything on my email, but if I put an error in the cronJob, like removing the last quotes, I get email with the error.

Then I press CTRL+X , I save and then I restart nginx and nothing.

I checked with crontab -l and the cronjobs are there.

All I want to do is make an URL from my website get executed every 1 minute. If I call the URL from my browser it seems to work.

I have UBUNTU and nGinx

Any help ?

Upvotes: 0

Views: 795

Answers (3)

NVG
NVG

Reputation: 3333

Found the problem. I had this in my code: require_once($_SERVER['DOCUMENT_ROOT'].'/something/cronJob.php').

Apparently $_SERVER['DOCUMENT_ROOT'] was empty.

So I fixed this using :

$path = str_replace('/something/cronJob.php','',$_SERVER['PHP_SELF']);

Upvotes: 1

Ed Heal
Ed Heal

Reputation: 60037

Here is a few steps to find out what is going wrong:

  1. Make a script [email protected] should be in that script and not in the crontab
  2. Does that script run Ok from the command line?
  3. Does crontab have the same environment variables

Upvotes: 0

fge
fge

Reputation: 121820

Use -O -.

The problem is that by default, wget will save its result to a file. You want the content to be dumped to stdout.

This means you'll have to cleanup your working directory of all cronJob.php.* files lying around too ;)

So:

* * * * * wget -q -O - "http://www.mywebsite.com/path/to/cronJob.php"

Upvotes: 4

Related Questions