im trying to set up a cronjob to run a PHP file. i just want to know if i am doing it right or not.
lets say the php is located at http://mysite.com/myscript/cronjob.php, and i want it to run every 3 hours.
i am very new to cronjobs so i apologise if it seems like i have no clue what i am doing.
Minute Hour Day Month Weekday Command
* */3 * * * http://mysite.com/myscript/cronjob.php
i want this to run that PHP script every 3 hours. will this work or do i have to use a different command?
Running the “systemctl” command along with the status flag will check the status of the Cron service as shown in the image below. If the status is “Active (Running)” then it will be confirmed that crontab is working perfectly well, otherwise not.
It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .
Check that your cron job is running by finding the attempted execution in syslog. When cron attempts to run a command, it logs it in syslog. By grepping syslog for the name of the command you found in a crontab file you can validate that your job is scheduled correctly and cron is running.
Cron Jobs allow you to automate specific commands or scripts on your server to complete repetitive tasks automatically. This can be a very resourceful tool as a Cron Job can be set to run by 15 minute or hourly increments, a day of the week or month, or any combination of these.
No, this won't work. A URL is not an executable, it is simply a URL.
You could put wget http://mysite.com/myscript/cronjob.php
for your command, but is that really what you want?
The best way (if the script is on the local server) is to call PHP directly:
php /var/www/myscript/cronjob.php
Almost, this should do it
* */3 * * * wget -q -o /dev/null http://mysite.com/myscript/cronjob.php
or with curl
* */3 * * * curl -s -o /dev/null http://mysite.com/myscript/cronjob.php
the -s / -q will silent the output and the -o will redirect the scripts output into /dev/null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With