Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:base-system:cron [2021/10/16 19:13] – [Goals] vgaeteradocs:guide-user:base-system:cron [2023/08/08 11:30] – Added my cronjob to keep last N snapshots of config torxgewinde
Line 9: Line 9:
 ===== Goals ===== ===== Goals =====
   * Run programs or scripts at a specific time.   * Run programs or scripts at a specific time.
 +  * Automate scheduled task management.
  
 ===== Web interface instructions ===== ===== Web interface instructions =====
Line 26: Line 27:
  
 # Apply changes # Apply changes
-service cron restart+/etc/init.d/cron restart
 </code> </code>
  
 This will edit the configuraion ''/etc/crontabs/root'' file in [[docs:guide-user:base-system:user.beginner.cli#editing_files|vi editor]]. This will edit the configuraion ''/etc/crontabs/root'' file in [[docs:guide-user:base-system:user.beginner.cli#editing_files|vi editor]].
  
-:!: There should be a end-of-line character on the last line of the crontab file.+:!: 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.
  
Line 61: Line 62:
 If you set the day of the week to 7, BusyBox will go bonkers and run your command every day. If you set the day of the week to 7, BusyBox will go bonkers and run your command every day.
  
-Table of shortcuts:+**Table of shortcuts:**
  
 ^ Shortcut ^ Equivalent ^ Description ^ ^ Shortcut ^ Equivalent ^ Description ^
Line 71: Line 72:
 | ''@midnight'' | ''0 0 * * *'' | Every day | | ''@midnight'' | ''0 0 * * *'' | Every day |
 | ''@hourly'' | ''0 * * * *'' | Every hour | | ''@hourly'' | ''0 * * * *'' | Every hour |
 +
 +:!:  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 131: Line 134:
 59 05 * * 1 /usr/bin/wol -h 192.168.1.255 xx:xx:xx:xx:xx:xx 59 05 * * 1 /usr/bin/wol -h 192.168.1.255 xx:xx:xx:xx:xx:xx
 # crontab must end with the last line as space or a comment # crontab must end with the last line as space or a comment
 +</code>
 +
 +==== Keep number of configs / snapshots of config ====
 +To keep a number N of configurations/settings at the directory "/root", you can also use cron. This way you can access and restore configurations of the past 100 days. The cronjob can easily be extended to copy the config to another device, to be able to replicate a broken OpenWRT device from scratch.
 +
 +<code bash>
 +#Make a new backup/configurations snapshot at nighttime 00:01 am, keep last N=100 snapshots
 +#01 00 * * * sysupgrade -b "/root/backup-${HOSTNAME}.tar.gz" # <-- keep just one config
 +01 00 * * * find "/root" -type f -name "backup-*.tar.gz" | sort -r | awk 'NR > 100' | xargs rm -f; sysupgrade -b "/root/backup-${HOSTNAME}-$(date +\%Y-\%m-\%d-\%H-\%M-\%S).tar.gz"
 </code> </code>
  
  • Last modified: 2023/10/14 06:55
  • by vgaetera