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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. CentOS / RHEL : How to Change the login shell of the user
  2. lvcreate: command not found
  3. eject: command not found
  4. lsmod: command not found
  5. How to uninstall python3-gi software package in Ubuntu
  6. tar Command Examples in Linux
  7. CentOS / RHEL : How to move a Volume Group from one system to another
  8. lsns: command not found
  9. mkfs.vfat Command Examples in Linux
  10. Configure MySQL Router to Auto Restart of Failure using systemd

You May Also Like

Primary Sidebar

Recent Posts

  • aws ec2: CLI for AWS EC2 (Command Examples)
  • aws cur – Create, query, and delete AWS usage report definitions (Command Examples)
  • aws configure – Manage configuration for the AWS CLI (Command Examples)
  • aws cognito-idp: Manage Amazon Cognito user pool and its users and groups using the CLI

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright