cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

os:linux:etc:cron:index.html



Linux

cron - How to use cron in Linux

/var/spool/cron/USER

This cron file can write by user.

Commands

CommandsNote
crontab -h Help
crontab -l
crontab -u USER -l
List
crontab -e
crontab -u USER -e
Edit
crontab -r
crontab -u USER -r
Remove

Format

1.minute  2.hour  3.dom  4.month 5.weekday   command

  1.  minute   Minute of the hour  0 th 59
  2.  hour     Hour of the day     0 to 23
  3.  dom      Day of the month    1 to 31
  4.  month    Month of the year   1 to 12
  5.  weekday  Day of the week     0 to 6 (0 = Sunday)

Example

00 12 * * * /home/shell/sample1.sh > /dev/null 2>&1        <- 12:00 Everyday
00  4 * * 6 /home/shell/sample2.sh  > /dev/null 2>&1       <-  4:00 Saturday
* *  * *  * /home/shell/test.sh 1>/dev/null 2>/dev/null


/etc/cron.d/FILE

Format

# 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

Example

/etc/cron.d/sysstat

# run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 1 1
# generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib/sa/sa2 -A


/etc/crontab

Format

# 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


/etc/cron.daily/


/etc/cron.weekly/


/etc/cron.hourly/


/etc/cron.monthly/




os/linux/etc/cron/index.html.txt ยท Last modified: 2017/11/29 by admin

Page Tools