How to : executing a block of code every 24 hours in a server? How to : executing a block of code every 24 hours in a server? linux linux

How to : executing a block of code every 24 hours in a server?


Open a shell.
(Stop crond service service crond stop)
Use vi (or other editor) to edit cron file or type "crontab -e" to make your edit.
After edit hit "ESC". Then ":wq", to save and quit.
(Start the service again service crond start)
Stopping and starting the service is not needed if you use crontab -e.

Your script should be running by now.Check the syntax here or here.To view the changes you've made type "crontab -l".

I hope this helps.


It's safe to ignore the advice to start and stop the cron daemon when editing a crontab(5). The crontab(1) utility notifies the cron daemon that the crontab(5) file needs to be reread and changes will take affect immediately. The only reason you would ever need to restart the cron daemon is if you edited the crontab(5) file directly without the crontab(1) utility.


First you will have to make a php file for this example cron.php

So whenever you go to this link www.yourdomain.com/crom.php the script is executed

Now add this link in cron job. To set up cron job on your server you can us this class of php