Red Hat Linux Reference Guide

Linux Introduction

VI-EDITOR

Process Management

Linux Installation

Disk Partitions & File System Management

Logical Volume Management - LVM

User & Group Administration

Package Management

Network File System - NFS

Domain Naming System - DNS

Apache HTTP Web Server

KickStart Installations

FTP server

BOOT PROCESS

Dynamic Host Configuration Protocol - DHCP

Job Scheduling

File Links

Swap Management

Log Management

Performance Management

Linux Troubleshooting

Linux Summary

Start Preparation Smartly

We have the collection to start prepartion smartly.

Start Assessment

Red Hat Linux Reference Guide

  DevOps Tech Hub

116 Followers

Cron Jobs Management


What is Job?

Running any command or  script in Linux system is called as Job.

What is Job Scheduling?

Sometimes these Jobs needs to be  executed  at certain specific times due to  business needs. Hence would need to depend on Job Scheduling utilities which can takes care of  running the command or script at specific times automatically on behalf you. So that you would not be required to  login to the system and run the command manually.

Types of Job Schedulers:

Linux supports below Job Schedulers to schedule a Job.

  1. cron
  2. at
  3. anacron

Cron Job Scheduler:

Cron Job Scheduler is more suitable for Jobs that needs to be  run repetitively and flexible to schedule job using cron syntax. Cron can not remember the job definitions hence if the system is down during the time the job needs to be run then that job will not be executed. 

at Job Scheduler:

'at' Job scheduler is more suitable for jobs that needs to be run only  once, 'at' scheduler do not support to run at interval periods.

anacron Job Scheduler:

'anacron'  Job Scheduler run the command only once in day, weekly, or monthly. anacron do not support to  run the jobs at interval periods. though the system is down during the  time of job needs to be run, 'anacron' can remember the  job and run the job once the server is back to operational.

Cron Syntax:

Cron Format:


Here,

  • Astrics (*) – Cron assume that all possibilities are matching
  • Multiple values – comma (,) is used to define multiple values at different times like 5,8,9 or mon,sat
  • Define range – hypen (-) is  used to define the range of values like 1-5or 10-30 or sun-tueri or jan-apr
  • Define multiple range – Multiple ranges can be defined using comma (,) and hypen (-) like jan-apr,oct-nov

How to schedule Cron Job:

[root@ ~]$crontab -e    ; it will open Vi-EDITOR to  add Job schedule

How to see list of Jobs Scheduled: 

[root@ ~]$crontab -l

How to see list of Jobs scheduled for specific user:

[root@ ~]$crontab -u username -l

Examples:

1. Schedule Job to run daily at 2AM

[root@ ~]$crontab -e

0 2 * * * /code/script.sh
~
~
~
~
~
~
~
~
~
"/tmp/crontab.iX3Gwb" 1L, 26C written
crontab: installing new crontab
[root@ ~]$

2. Schedule Job to  run every 10 minutes

*/10 2 * * * /code/script.sh

3. Schedule Job to  run every Monday at 4 PM

0 4 * * 1 /code/script.sh

4. Schedule Job to run alternate days at 4 PM

0 4 */2 * * /code/script.sh


Previous Next