Geody Labs


# Main Index: Debian Linux Magic Spells Cheat Sheet (one liners, how to, tips and tricks)

# CronTab (Scheduled Jobs)

Scheduled jobs with CronTab:

# Edit CronTab file
crontab -e # Edit CronTab file using the default editor or the one set in export EDITOR=jed ; export VISUAL=jed ; # (or another editor)

Format:
# Line of comments start with the dash character (#)
minute (0-59) hour (0-23) day of month (1-31) month (1-12) day of week (0-6, Sunday=0) COMMAND

# Use asterisks to specify any occurrence of the time parameter
* * * * * echo "test" # execute the command every minute (not recommended)
30 * * * 1 echo "test" # execute the command every 30 minutes, every monday

# separate multiple istances of the same time parameter with a comma (,)
15,30,45 * * * 1,3,5 echo "test" # execute the command every 15 minutes, every monday, wednesday, friday

# separate two istances with a dash (-) to create a time range
0 0,12 * 6-9 1-5 echo "test" # execute the command at midnight amd at twelve, every day from monday to friday, during every month from June to September

# Percent character (%) must be escaped (\)
30 * * * 1 touch /PATH/file_$(date +\%Y\%m\%d).txt

# Normally, crontab sends a mail to the user with the output of the command executed, including errors. Append ">/dev/null 2>&1" to the command line to prevent this behaviour
* * * * * echo "test">/dev/null

# list all scheduled jobs
crontab -l

# erase the crontab file (not recommended because remove all jobs, including ones that might be necessary for the system, you'd better edit the crontab files and delete entries manually)
crontab -r




Please DONATE to support the development of Free and Open Source Software (PayPal, Credit Card, Bitcoin, Ether)

Page issued on 25-Sep-2022 04:46 GMT
Copyright (c) 2022 Geody - Legal notices: copyright, privacy policy, disclaimer