1

I am running a php script using cron. The name of the file is : PriceChecker.php . This is my cron script

# m h  dom mon dow   command
0 07,11,16,20 * * * php /var/www/mainsite/PriceChecker.php
* * * * * /var/www/mainsite/pricecheck.sh

The shell script is:

#!/bin/bash
php PriceChecker.php >logger.log

The first line is the original. The second is for testing I have tried various variations including: /usr/bin/php /var/www/mainsite/PriceChecker.php

If I log the out in the cron php /var/www/mainsite/PriceChecker.php > logfile.log

The logfile is created, but is empty

6
  • 1
    Guessing without knowing anything else about scripts? I don't think you'll find an answer here :) Commented Nov 29, 2013 at 13:11
  • When you debug line-by-line the PriceChecker.php, at what lines does the code break? And what is written in the error log? Commented Nov 29, 2013 at 13:11
  • What is your script about ? Are you sure it isn't executed ? What is the expected output ? Try to log something on a file using your PHP script itself. Commented Nov 29, 2013 at 13:12
  • It's always safer to refer to the php binary with an absolute path (like /usr/bin/php - execute where php to figure out what to use). Reason is that typically cron offers very little PATH to the tasks it runs. Commented Nov 29, 2013 at 13:14
  • I did that. I used /usr/bin/php. Didnt work Commented Nov 29, 2013 at 13:14

3 Answers 3

2

Same as here, I think Cannot get PHP cron script to run

You forgot to specify the user name you want your script to be run as.

Sign up to request clarification or add additional context in comments.

8 Comments

root. The same username as the one setting the cron, in my case root
You don't need it if you use crontab -u myUser -e
Right. As said before; full paths are better, try to run your script in a root terminal to test it
it works when i run it in the terminal. I am using the following pricechecker.sh : /usr/bin/php /var/www/mainsite/PriceChecker.php >/var/www/mainsite/logger.log
Like I said : try to log something on a file using your PHP script itself.
|
1

Specify the full path of the PHP file to be execute

1 Comment

that wasn't the issue. I mentioned that I used the full path in the answer
0

Okay what worked was CDing into the directory of the script

https://serverfault.com/questions/97828/php-from-command-line-path-problems/97881#97881

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.