Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install cron

Tags:

php

cron

I want to run PHP scripts automatically on a schedule. I learned about CRON recently. But I don't know how to install and use it.

I'm using PHP, CSS, HTML, and running on XAMP apache server on localhost. How do I install and use Cron?

like image 485
Rajasekar Avatar asked Nov 26 '09 08:11

Rajasekar


People also ask

Where is cron installed?

The crontab files are stored in /var/spool/cron/crontabs . Several crontab files besides root are provided during SunOS software installation (see the following table). Besides the default crontab file, users can create crontab files to schedule their own system events.

Where is cron installed Linux?

The cron jobs are listed in crontab files and are located in the cron spool area /var/spool/cron/crontabs. Cron searches for these files and load them in the memory for execution. Another file cron read is /etc/crontab. In Debain and Ubuntu /etc/crontab executes programs written under directories /etc/cron.


2 Answers

Do you have a Windows machine or a Linux machine?

Under Windows cron is called 'Scheduled Tasks'. It's located in the Control Panel. You can set several scripts to run at specified times in the control panel. Use the wizard to define the scheduled times. Be sure that PHP is callable in your PATH.

Under Linux you can create a crontab for your current user by typing:

crontab -e [username] 

If this command fails, it's likely that cron is not installed. If you use a Debian based system (Debian, Ubuntu), try the following commands first:

sudo apt-get update sudo apt-get install cron 

If the command runs properly, a text editor will appear. Now you can add command lines to the crontab file. To run something every five minutes:

*/5 * * * *  /home/user/test.pl 

The syntax is basically this:

.---------------- minute (0 - 59)  |  .------------- hour (0 - 23) |  |  .---------- day of month (1 - 31) |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...  |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat  |  |  |  |  | *  *  *  *  *  command to be executed 

Read more about it on the following pages: Wikipedia: crontab

like image 110
TheGrandWazoo Avatar answered Sep 25 '22 01:09

TheGrandWazoo


Install cron on Linux/Unix:

apt-get install cron 

Use cron on Linux/Unix

crontab -e 

See the canonical answer about cron for more details: https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it

like image 39
Eric Leschinski Avatar answered Sep 25 '22 01:09

Eric Leschinski