• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Defining System Jobs Using Cron under Linux

by admin

The cron daemon can be configured to run scheduled system jobs. For system jobs, the user with whose permissions the command is run must also be specified. Enter the username between the time definition (the first five fields) and the command (which now becomes the seventh field).

You define system jobs in the /etc/crontab file or in files in the /etc/cron.d/ directory. A default crontab in CentOS/RHEL system is as shown below.

# cat /etc/crontab 
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- 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
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
NOTE: While you can add additional lines to /etc/crontab, you should not delete the default lines.

The job defined in the above /etc/crontab file runs the scripts contained in the following directories at the intervals indicated:

Directory Interval
/etc/cron.hourly /etc/cron.hourly Jobs that run on an hourly basis.
/etc/cron.daily Jobs that run on a daily basis.
/etc/cron.weekly Jobs that run on a weekly basis.
/etc/cron.monthly Jobs that run on a monthly basis.
# ls -lrt /etc/cron.hourly/
total 4
-rwxr-xr-x. 1 root root 392 Mar 29  2017 0anacron
[root@jamiericho4 ~]#  ls -l /etc/cron*
-rw-------. 1 root root   0 Mar 29  2017 /etc/cron.deny
-rw-r--r--. 1 root root 451 Dec 27  2013 /etc/crontab
/etc/cron.d:
total 16
-rw-r--r--. 1 root root 128 Mar 29  2017 0hourly
-rw-r--r--. 1 root root 173 Sep 23  2016 awslogs
-rw-r--r--. 1 root root 179 Sep 23  2016 awslogs_log_rotate
-rw-r--r--. 1 root root 108 Jun 13  2017 raid-check
/etc/cron.daily:
total 16
-rwx------. 1 root root 219 Jan 24  2017 logrotate
-rwxr-xr-x. 1 root root 618 Mar 17  2014 man-db.cron
-rwx------. 1 root root 208 Feb  4  2016 mlocate
-rwx------. 1 root root 256 Sep  1 10:34 rhsmd
/etc/cron.hourly:
total 4
-rwxr-xr-x. 1 root root 392 Mar 29  2017 0anacron
/etc/cron.monthly:
total 0
/etc/cron.weekly:
total 0

Filed Under: Linux

Some more articles you might also be interested in …

  1. Example of using getnstimeofday in Linux kernel
  2. CentOS / RHEL : Resize (extend) non-root EXT3/4 filesystem on non-LVM device (hard disk partition)
  3. collectd : command not found
  4. apport-bug Command Examples in Linux
  5. atool Command Examples in Linux
  6. yum Command Examples in Linux
  7. “az storage table” Command Examples
  8. chfn: command not found
  9. Linux / UNIX : How to send mails with attachments using mailx command
  10. Configure Network Bonding in Ubuntu Server

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright