Skip to main content

Schedule Task on Ubuntu Using Cron Jobs

This article is about the Cron Job and how to schedule task on Ubuntu machine using Cron jobs. The cron is a time-based job scheduler in Unix-like computer operating systems.

The word "Crontab" is derived from chronos (Time in Greeks) and tab stands for table. Crontab is useful for scheduling the task automatically run at regular interval as the background process. Crontabs are useful for taking backups, synchronizing files, etc.

Before doing all other stuffs, first we will change the default editor to nano editor by typing the following command in terminal.
export EDITOR="nano"
To schedule new /edit crontab entries for specific time
crontab -e
This will open the nano editor with the default commented scheduling with five stars to allow our task scheduling. we can schedule our tasks here as follows
* * * * * /home/harishshan/example.sh
This will execute the example.sh for every minute. The following is an easy way to remember the crontab format
* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)
If you leave star(asterisk), it means every.If you leave ?, it means any.

Examples:

Schedule Crontab Syntax
Daily 10AM 0 10 * * *
October 12th 12.20 PM 20 12 12 10 *
5 After 4 Every Sunday 5 4 * * 0
Every 15 minutes */15 * * * *
Every Friday 1 AM 0 1 * *5
  1. To list crontab entries
  2. crontab -l
    
  3. To list scheduled cron jobs of a particular user
  4. crontab -u root -l
    
  5. To remove all crontab entry
  6. crontab -r
    
  7. To prompt before deleting crontab
  8. crontab -i -r
    
Note: By default crontab saves the output in user's mailbox which we configured as MAILTO in the crontab
MAILTO="yourname@yourdomain.com"
Instead you can configure to output to separate logfile like as follows
* * * * * /home/harishshan/example.sh >> /var/log/example_log.log 2>&1
Where
  1. /var/log/example_log.log represents log file
  2. 1 represents STDOUT
  3. 2 represents STDERR

Comments

Popular posts from this blog

Install Hadoop 2.5.1 on Windows 7 - 64Bit Operating System

This post is about installing Single Node Cluster Hadoop 2.5.1 (latest stable version) on Windows 7 Operating Systems.Hadoop was primarily designed for Linux platform. Hadoop supports for windows from its version 2.2, but we need prepare our platform binaries. Hadoop official website recommend Windows developers to use this build for development environment and not on production, since it is not completely tested success on Windows platform. This post describes the procedure for generating the Hadoop build for Windows platform. Generating Hadoop Build For Windows Platform Step 1:Install Microsoft Windows SDK 7.1 In my case, I have used Windows 7 64 bit Operating System. Download Microsoft Windows SDK 7.1 from Microsoft Official website and install it. While installing Windows SDK,I have faced problem like C++ 2010 Redistribution is already installed. This problem will happen only if we have installed C++ 2010 Redistribution of higher version compared to the Windows SDK. ...

Install Spring Tool Suite on Ubuntu

This post is about installing Spring Tool Suite (STS) on Ubuntu. The Spring Tool Suite is an Eclipse-based development environment that is customized for developing Spring applications. Step 1: Download the latest Spring Tool Suite for Linux from STS official website: http://spring.io/tools/sts/all  Step 2: Extract into any folder which you prefer. My extracted Spring Tool Suite locations is /home/harishshan/springsource Step 3: Create the Menu icon for quick access sudo nano /usr/share/applications/STS.desktop Step 4: Enter the following content [Desktop Entry] Name=SpringSource Tool Suite Comment=SpringSource Tool Suite Exec=/home/harishshan/springsource/sts-3.4.0-RELEASE/STS Icon=/home/harishshan/springsource/sts-3.4.0-RELEASE/icon.xpm StartupNotify=true Terminal=false Type=Application Categories=Development;IDE;Java; Step 5: Now you can check from Quick Menu by typing " Spring "

How to fix Kindle wrong time left in chapter book

The most of kindle reader use the time left in chapter or time left in book options provided at left bottom of the page to estimate completing the book or the current chapter. But sometimes it was not  accurate and displaying 5 min left in chapter instead of 30 min left in chapter. To fix this issue just type ;ReadingTimeReset at search field and enter. Kindly refer the photo for the same.