How to run reboot command in openwrt only once at a particular time using crontab?

Viewed 20605

I want to reboot my device ,which has Openwrt os .I want the command run using crontab and execute only once.

4 Answers

If you want to run only once then better ssh the openwrt and go the terminal and type reboot. Which will reboot the system.

In case if you want to runt the reboot at specific time then you can use cronjob. Which has the following syntax

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Use the following command in your openwrt command line to open crontab

crontab -e //-e stands for edit

Now based on the above syntax you can tell when to run the script

Eg : To run on January 1st of every year you can write the following command

* * 1 1 * reboot

Save the file and it will do the trick.

I am assuming by saying only once, you meant only once in a day? If that is the case then do the following

crontab -e

Add the following line there and save the file.

15 3 * * * reboot

Now reboot the cron service

/etc/init.d/cron restart

It will reboot the router everyday at 03:15 AM.

Openwrt crontab does not support @reboot, so you can use once a minute command:

*****

and then check in your script to be executed if there is no instance of it running on the shell.

But, you also can use rc.local and put your script on it. Just don't forget to make rc.local executable permission, sometimes it needs changing permissions.

Another option is also running in /etc/init.d/ if it is a service.

Related