How do I set Cron Job scheduler

Cron is the time-based job scheduler in Unix-like computer operating systems. Cron enables users to schedule jobs (commands or shell scripts) to run periodically at certain times or dates. It is commonly used to automate system maintenance or administration, though its general-purpose nature means that it can be used for other purposes, such as connecting to the Internet and downloading emails.

Cloudjiffy gives me a possibility to run my programs at specified time with a help of cron, which receives my instructions and performs any tasks following the derived scenarios. I can use this opportunity to perform periodic tasks, e.g.:

  • logs clearing
  • backing up
  • scripts running

Check out the example below.

Create the environment

  1. Log into CloudJiffy dashboard and click on Create environment button.





  2. In the Environment topology window choose the application server and database I want to use (for example, Tomcat and MySQL). Type the name of the environment and click Create.




In a minute my environment with both Tomcat and MySQL nodes will be created.

1. Click the Config button for my application server.



2. Upload scripts I want to run to the following folder:

  • home - if I use Java server in my environment (as we do in this instruction)
  • the folder where my application is stored - if I use PHP server in my environment

        

1. Click the Config button for my database (MySQL or MariaDB).



2. Upload the scripts I want to perform to the scripts folder.



Note: Script I want to perform should be an executable file. If it isn’t, I can use built-in interpreters, such as BashPerlPythonSEDAWK, or Expect (depending on the script I use).

  1. In the already opened configurations tab navigate to the cron folder and open the {nodeName} file.



2. Here I can write all necessary commands to schedule my tasks. They should be composed in a way so that crontab will understand them. The basic format of a crontab schedule consists of 6 fields separated by spaces.

1
{minute} {hour} {day} {month} {day-of-week} {command-line-to-execute}

 

Field Range of values
minute 0-59
hour 0-23
day 1-31
month 1-12
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 I want to run

 

While stating these values I need to follow the next standards:

  • The fields have to be in that exact order, with no empty or missing fields.
  • If needed I 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” field means “to run every hour”.
  • The “/” character is used to specify additional frequency assignments. For example, “* / 3” in the “hour” means “every three hours”.
  • For each individual parameter, I can specify multiple values separated by commas. For example, if in the “hour” I type “1,6,19”, the job will run “at 1:00, at 6:00, and 19 hours”. I can also specify the interval, for example, “8-17” would mean that the program will be run “every hour from 8 to 17 inclusive”.

Pay attention that I should specify a full path to my script in the cron command. Depending on the location of my script the path can be as one of the following:

  • home folder for Java compute nodes:
    • /opt/tomcat/temp/{scriptName} - Tomcat, TomEE
    • /opt/jetty/home/{scriptName} - Jetty
    • /opt/glassfish3/temp/{scriptName} - GlassFish
  • folder with my application files & scripts for PHP compute nodes:
    • /var/www/webroot/{appFolder}/{scriptName}
  • scripts folder for MySQL/MariaDB databases:
    • /var/lib/jelastic/bin/{scriptName}

3. For example, if my script is located in the home folder of Tomcat and I want it to be performed every minute, my command line can look like this example:

1
*/1 * * * *  /opt/tomcat/temp/test.sh



Tip: If my script does not have executable flag and I use built-in interpreters, such as Bash, Perl, Python, SED, AWK or Expect (depending on my script), I should add the following paths after time settings for explicit specifying the interpreter:

  • /bin/bash - for Bash
  • /usr/bin/python - for Python
  • /usr/bin/perl - for Perl
  • /bin/sed - for SED
  • /bin/awk - for AWK
  • /usr/bin/expect - for Expect
  • /usr/bin/php - for php-interpreter

In this case my command will be as following:

1
*/1 * * * *  /bin/bash /opt/tomcat/temp/test.sh



4. Please make sure there is a blank line after the last cronjob entry.

5. Save the changes in order to apply the settings.

That’s all. As I can see, it is pretty easy to schedule my tasks with Cloudjiffy. Enjoy!

 Cronjob is a nifty tool to prevent problems from occurring and provide me with peace of mind. As I see, it is very easy to schedule my tasks with CloudJiffy new feature. Enjoy!


Was this article helpful?

mood_bad Dislike 0
mood Like 1
visibility Views: 12332