Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

crontab in linux

crontab -e						

10 * * * * /bin/sh test.sh    # every hour at 10"
0 */4 * * * /bin/sh test.sh   # every 4 hours at 0"
0 9-17 * * * /bin/sh test.sh  # every hour at 0" between 9 and 17
0 2 * * * /bin/sh test.sh     # daily at 2am
0 0 * * MON /bin/sh test.sh   # every Monday at 0am
0 0 * * 1-5 /bin/sh test.sh   # daily from Monday to Friday at 0am
0 0 * * 0 /bin/sh test.sh     # weekly on Sunday
0 0 1 * * /bin/sh test.sh     # monthly (1rst day at 0am)
0 0 1 */3 * /bin/sh test.sh   # every quarter (1st day at 0am)
0 0 1 1 * /bin/sh test.sh     # yearly (01/01)
Comment

syntax crontab

# 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 command to be executed
example :
# 50 12 * * * ----- run every day at 12.50

# */5 * * * * ----- run every 5 minutes
Comment

crontab command

crontab -e						# to edit (then 'i': insert, ':wq!': save and quit)
10 * * * * /bin/sh backup.sh    # every hour at 10"
0 */4 * * * /bin/sh backup.sh   # every 4 hours at 0"
0 9-17 * * * /bin/sh backup.sh  # every hour at 0" between 9 and 17
0 2 * * * /bin/sh backup.sh     # daily at 2am
0 0 * * MON /bin/sh backup.sh   # every Monday at 0am
0 0 * * 1-5 /bin/sh backup.sh   # daily from Monday to Friday at 0am
0 0 * * 0 /bin/sh backup.sh     # weekly on Sunday
0 0 1 * * /bin/sh backup.sh     # monthly (1rst day at 0am)
0 0 1 */3 * /bin/sh backup.sh   # every quarter (1rst day at 0am)
0 0 1 1 * /bin/sh backup.sh     # yearly (01/01)
Comment

cron crontab

# Adding tasks easily
echo "@reboot echo hi" | crontab

# Open in editor
crontab -e

# List tasks
crontab -l [-u user]
Comment

crontab sample command

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- weekday (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  user command to be executed
10 * * * * /bin/sh backup.sh    # every hour at 10"
Comment

crontab syntax

.---------------- 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 
|  |  |  |  |
*  *  *  *  *  command to be executed
Comment

PREVIOUS NEXT
Code Example
Shell :: bash find file 
Shell :: openni 2 ros package install 
Shell :: debian libc-client.a). Please check your c-client installation 
Shell :: wp cli change tagline 
Shell :: install adminlte 
Shell :: linux make symlink 
Shell :: Comandos Útiles Docker 
Shell :: adobe reader for ubuntu 20.04 
Shell :: install vmware workstation linux mint 
Shell :: nginx create alias 
Shell :: pretty git branch graph print 
Shell :: particular screenshot in ubuntu 
Shell :: linux kill all zombie processes 
Shell :: k8s roll back to previous deployment 
Shell :: kivy vim plugin 
Shell :: expo uninstall package 
Shell :: ubuntu bluetooth microphone not working 
Shell :: git status 
Shell :: Using git filter-branch to Git Change Commit Author 
Shell :: Linux install from .tar.gz 
Shell :: make tar.gz 
Shell :: install owlready2 
Shell :: kubectl download 
Shell :: amazon linux wireguard 
Shell :: check g++ on ubuntu 
Shell :: git bad object 
Shell :: npm windows error 
Shell :: how to move many folders linux 
Shell :: copy all in a folder here command terminal 
Shell :: copy only directory contents to another directory 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =