• 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. How to disable NetworkManager on CentOS / RHEL 7
  2. lvremove failing to remove volume after using ‘shred’ command
  3. Linux OS Service ‘NetworkManager’
  4. “The requested URL returned error: 403 Forbidden” – yum update error
  5. How to Create a Custom Log File Rotation by logrotate in Linux
  6. CentOS / RHEL : How to set chroot jail for vsftp for all the users
  7. ‘lxc_cgfs – Device or resource busy – failed to set memory.use_hierarchy to 1; continuing’ – error while starting LXC container
  8. “Failed to start test.mount: Unit is not loaded properly: Invalid argument.” – While mounting a fileystem using systemd
  9. How to find all the sparse files in Linux
  10. LVM ISCSI Physical Volume Not Available After Server Reboot

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright