Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:base-system:cron [2020/10/04 10:30] – use consistent naming vgaetera | docs:guide-user:base-system:cron [2023/08/08 11:30] – Added my cronjob to keep last N snapshots of config torxgewinde | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Scheduling tasks ====== | + | ====== Scheduling tasks with cron ====== |
| {{section> | {{section> | ||
| ===== Introduction ===== | ===== Introduction ===== | ||
| - | * OpenWrt | + | * OpenWrt |
| - | * This how-to describes the methods | + | * This how-to describes the method |
| + | * See also [[docs: | ||
| - | ===== Web interface ===== | + | ===== Goals ===== |
| + | * Run programs or scripts at a specific time. | ||
| + | * Automate scheduled task management. | ||
| + | |||
| + | ===== Web interface | ||
| Set up cron jobs using web interface. | Set up cron jobs using web interface. | ||
| - | - Navigate to **[[http:// | + | - Navigate to **LuCI -> System -> Scheduled Tasks**. |
| - Edit the configuration and click the **Save** button. | - Edit the configuration and click the **Save** button. | ||
| - | ===== Command-line | + | ===== Command-line |
| Set up cron jobs using command-line interface. | Set up cron jobs using command-line interface. | ||
| Line 27: | Line 32: | ||
| This will edit the configuraion ''/ | This will edit the configuraion ''/ | ||
| - | :!: There should be a end-of-line | + | :!: There should be a EOL character on the last line of the crontab file. |
| Just leave an empty line at the end to be sure. | Just leave an empty line at the end to be sure. | ||
| ===== Task specification ===== | ===== Task specification ===== | ||
| Each line is a separate task written in the specification: | Each line is a separate task written in the specification: | ||
| + | |||
| < | < | ||
| * * * * * command to execute | * * * * * command to execute | ||
| Line 44: | Line 50: | ||
| Examples of time specification: | Examples of time specification: | ||
| - | + | ||
| - | ^ min\\ 0-59 ^ hour\\ 0-23 ^ day/month\\ 1-31 ^ month\\ 1-12 ^ day/week\\ 0-6 ^ Description ^ | + | ^ min\\ 0-59 ^ hour\\ 0-23 ^ day/month\\ 1-31 ^ month\\ 1-12 ^ day/week\\ 0-6 ^ Description ^ |
| - | | | + | | */5 | * | * | * | * | Every 5 minutes | |
| - | | | + | | 12 | */3 | * | * | * | Every 3 hours at 12 minutes | |
| - | | | + | | 57 | 11 | 15 | 1,6,12 | * | At 11:57 Hrs on 15th of Jan, June & Dec | |
| - | | | + | | 25 | 6 | * | * | 1-5 | At 6:25 AM every weekday (Mon-Fri) | |
| - | | | + | | 0 | 0 | 4, |
| - | | 5,10 | + | | 5,10 | 9,14 | 10 | * | 0,4 | At 9:05AM, 9:10AM, 2:05PM and 2:10PM every Sunday and Thursday | |
| :!: 0 (zero) is treated as Sunday. | :!: 0 (zero) is treated as Sunday. | ||
| - | If you set the day of the week to 7, busybox | + | If you set the day of the week to 7, BusyBox |
| + | |||
| + | **Table of shortcuts: | ||
| + | |||
| + | ^ Shortcut ^ Equivalent ^ Description ^ | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | | '' | ||
| + | |||
| + | :!: Time shortcuts are not enabled by default. Shortcuts require compiling busybox with FEATURE_CROND_SPECIAL_TIMES enabled in the busybox compile options. | ||
| ===== Troubleshooting ===== | ===== Troubleshooting ===== | ||
| Line 69: | Line 88: | ||
| * [[man> | * [[man> | ||
| * [[https:// | * [[https:// | ||
| - | * [[http:// | + | * [[http:// |
| ==== Periodic reboot ==== | ==== Periodic reboot ==== | ||
| Line 96: | Line 115: | ||
| There is usually no programmable circuitry to actually power off the unit. | There is usually no programmable circuitry to actually power off the unit. | ||
| '' | '' | ||
| - | |||
| - | However, a more flexible approach is to use use the [[packages: | ||
| - | |||
| - | <code bash> | ||
| - | opkg update | ||
| - | opkg install watchcat luci-app-watchcat | ||
| - | </ | ||
| ==== Periodic network restart ==== | ==== Periodic network restart ==== | ||
| Line 112: | Line 124: | ||
| ==== Alarm clock ==== | ==== Alarm clock ==== | ||
| - | If you have [[wp> | + | If you have [[wp> |
| When DST starts in central Europe, clocks advance from 02:00 CET to 03:00 CEST on last Sunday in March. | When DST starts in central Europe, clocks advance from 02:00 CET to 03:00 CEST on last Sunday in March. | ||
| - | Six day before that, you could make your WOL wake you 10 minutes earlier. | + | Six day before that, you could make your WoL wake you 10 minutes earlier. |
| - | Later won't work, you'll be late ;-) | + | Later won't work, you'll be late. |
| When DST ends in central Europe, clocks retreat from 03:00 CEST to 02:00 CET on last Sunday in October. | When DST ends in central Europe, clocks retreat from 03:00 CEST to 02:00 CET on last Sunday in October. | ||
| <code bash> | <code bash> | ||
| - | #min hour day month dayofweek command | + | # min hour day month dayofweek command |
| - | 59 05 * * 1 / | + | 59 05 * * 1 / |
| - | #crontab must (as fstab) | + | # crontab must end with the last line as space or a comment |
| + | </ | ||
| + | |||
| + | ==== Keep number of configs / snapshots of config ==== | ||
| + | To keep a number N of configurations/ | ||
| + | |||
| + | <code bash> | ||
| + | #Make a new backup/ | ||
| + | #01 00 * * * sysupgrade -b "/ | ||
| + | 01 00 * * * find "/ | ||
| </ | </ | ||