Comment on 2024-09-16 at 10:37 EEST

As of now, every hour is too often. I do it this way:

To create a cron job that runs a script at 9:25 AM, 12:25 PM, 3:25 PM, and 6:25 PM, you can use the following cron expression:

25 9,12,15,18 * * * service network restart
Breakdown of the cron expression:
  • 25: The job runs at 25 minutes past the hour.
  • 9,12,15,18: The hours when the job runs (9 AM, 12 PM, 3 PM, 6 PM).
  • *: Every day of the month.
  • *: Every month.
  • *: Every day of the week.

Make sure to replace /path/to/your/script.sh with the actual path to your script. You can add this line to your crontab file by editing it using crontab -e.


Modified openwrt balcony router, so it will restart network service every 4 hours:

Periodic network restart

Restart all your network (lan, wan and wifi) every 3 hours is this:

0 */3 * * * service network restart

Set up cron jobs using command-line interface.

# Edit configuration
crontab -e 
 
# Show configuration
crontab -l
 
# Apply changes
service cron restart

This will edit the configuraion /etc/crontabs/root file in vi editor.

There should be empty line, according to the manual, Scheduling tasks with cron:

:!: 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.


Task specification

Each line is a separate task written in the specification:

* * * * * command to execute
- - - - -
| | | | |
| | | | ----- Day of week (0 - 6) (Sunday =0)
| | | ------- Month (1 - 12)
| | --------- Day (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

Examples of time specification: 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,12,26 	* 	* 	At midnight on 4th, 12th and 26th of every month
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. If you set the day of the week to 7, BusyBox will go bonkers and run your command every day.


Table of shortcuts:

Shortcut 	Equivalent 	Description
@reboot 	Run once, at startup
@yearly 	0 0 1 1 * 	Every year
@annually 	0 0 1 1 * 	Every year
@monthly 	0 0 1 * * 	Every month
@weekly 	0 0 * * 0 	Every week
@daily 	        0 0 * * * 	Every day
@midnight 	0 0 * * * 	Every day
@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

You can read log messages with:

logread -e cron

Not all messages are logged, to increase logging change cronloglevel option.