Simplifying Admin Tasks: Use Cron Jobs in Jelastic
We know you have been waiting for this. And it’s finally here!
We have some cool news: you can now run Cron tasks on Jelastic! Thanks to all of our active users, this great feature is now available in Jelastic PaaS
We have added this new capability via our new VDS feature
Note: this feature is available starting with Jelastic version 1.8.2 and is a paid add-on.
Before we install it, let’s do a quick recap of what cron is and why so many developers love it.
Basicaly, cron is the time-based job scheduler in Unix-like OSs. Server and website administration can be automated and simplified with the use of Cron jobs. Cron jobs are commonly used by webmasters to schedule mundane, time-consuming and repetitive tasks that can be handled by simple programming. Cron jobs are constantly running in the background on the web server and are powered by files known as crontabs, which contain all of the timing and task execution details.
And now Jelastic gives you the capability to run your programs at a specified time with a help of cron, which receives your instructions and performs any tasks following derived scenarios. You can use this opportunity to perform periodic tasks. To do this, just follow these instructions: start by creating an environment and establishing an SHH connection as described here
Setting up cron
1. First of all you need to decide which program you want to run and get its full path at the server disk. The path can look like: /your_directory/whatever.pl.
2. In the opened console (which you’ve got after your SSH connection) enter the command:
3. Write the schedule for your task in such a way that cron tab will understand it.
The basic format of a crontab schedule consists of 6 fields, separated by spaces, formatted as follows:
minute hour day month day-of-week command-line-to-execute
The acceptable values for each of the 6 fields are:
|Field||Range of values|
|day-of-week||0-7 (where both 0 and 7 mean Sun,|
1 = Mon, 2 = Tue, etc)
|command-line-to-execute||the path to the program you want to run|
The fields have to be in that exact order, with no empty or missing fields.
- If needed you can use a wildcard character – “*” (the asterisk). In a crontab file it represents every possible value for the field. For example, specifying :*” in the “hour” means “to run every hour.”
- ‘/‘ character is used to specify additional frequency assignments. For example, ‘* / 3’ in the “hour” means “every three hours.”
- For each individual parameter, you can specify multiple values separated by commas. For example, if in the “hour” you type 1,6,19, the job will run at 1:00 am, at 6:00 am and 19 hours. You can also specify the interval, for example, 8-17 would mean that the program will be run every hour from 8 to 17 inclusive.
So, for example, your command line can look like this:
And in this case it means that the /your_directory/whatever.pl. program will be run every 3 hours.
If you want to run PHP-scripts with the stated period, you can do that with a help of wget. For that the command-line-to-execute should look like the next example:
To save and exit type :q and press Enter.
Congratulations! You have now scheduled your tasks.