I am trying to run PHP file on path /var/www/html/rss_feed/mirror.php
through cron tabs. For this I performed the below steps.
sudo crontab -e
Then I edited the file by inserting the following code
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# avt 5 a.m every week with:
# 0 5 * * 1 tar -zcf /ar/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
*/2 * * * * /usr/bin/php /var/www/html/rss_feed/nbt_times.php
#
# m h dom mon dow command
As you can see below is the line of code inserted to schedule cron tab after every 2 minutes to run a php file.
*/2 * * * * /usr/bin/php /var/www/html/rss_feed/nbt_times.php
I even tried following
2 * * * * lynx -dump http://192.168.0.232/rss_feed/mirror.php > /dev/null 2>&1
and even this
2 * * * * /your/path/to/php /var/www/html/rss_feed/nbt_times.php
and many more formats from different articles.
The php script is not running. Do I need to put the code somewhere else? Or I am on the wrong way. Can you please help me find out what is the issue.
It should work but need to get some clarifications here, file name seems to be different one time its mirror.php and another time its nbt_times.php
which php file has to run on the specific time that has to be specified. As you specified you're running /var/www/html/rss_feed/mirror.php then, then specify mirrror.php on your first command .
The 2nd and third command will run the job for 2nd minute of every hour. like (4:02,5:02,6:02, etc)
Try this crontab
*/2 * * * * /usr/bin/php /var/www/html/rss_feed/mirror.php
This will run for every 2 mins hope this works.
Try with php5-cli:
*/2 * * * * /usr/bin/php5-cli -f /var/www/html/rss_feed/nbt_times.php
Also add write to logs and see them after minute:
* * * * * /usr/bin/php /var/www/html/rss_feed/nbt_times.php >>log.log 2>>log.err
Check permissions of your php-file. Make 0777 for checking. Try create the simplest php file with one row and run it via cron.