tags:

views:

275

answers:

2

I need to run a php file every minute so I tried to set a cronjob from the cpanel but it's sending mail with the message "could not open the input file:"

My php file is inside public_html/schoolerp/cron.php

I did:

/usr/local/bin/php -f /public_html/schoolerp/cron.php

Am I doing something wrong please tell me if I am setting it right, and if I am wrong please help me correct it ...

+1  A: 

Not sure if this is a complete fix, but you are using absolute pathing for '/public_html/schoolerp/cron.php', when that doesn't seem very likely to be correct. You might be looking for a relative path of 'public_html/schoolerp/cron.php' (note the lack of preceding '/'). You may just want to use the proper absolute path starting from the root of the filesystem though.

byte
+2  A: 
  • Use absolute paths
  • Make sure that the script is accessible, check access permissions of file/directories on path
  • cron by default will take all the output of your script and send it to your email

You can redirect the output of your command to file or /dev/null to prevent cron from sending email. I would suggest redirect to local file for future references, it's good for debugging and when something goes wrong.

I think something like this should do:

/usr/local/bin/php -f /public_html/schoolerp/cron.php > /logs/mylog.txt 2>&1

Redirect to mylog.txt file and append stderror to stdout so that both stderror and stdout is in log file.

stefanB
Good thorough answer, much moreso than mine. +1
byte