• 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. doctl serverless: Manage serverless functions
  2. Unable to Run X Applications Through SSH in Linux
  3. sort Command Examples in Linux
  4. certbot: command not found
  5. How to copy directories recursively using rsync while excluding specific files
  6. YUM command examples to install, remove and upgrade packages
  7. eva: Simple calculator REPL, similar to bc, with syntax highlighting and persistent history
  8. aws-shell: command not found
  9. yum Command Examples in Linux
  10. How to Provide Credentials From a File While Mounting CIFS Share in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright