Scheduled reboot using Cron not working.

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
cyberpranav
DD-WRT Novice


Joined: 01 Jan 2019
Posts: 20

PostPosted: Wed Nov 02, 2022 1:57    Post subject: Scheduled reboot using Cron not working. Reply with quote
Hi DD-WRT team.

Thanks a lot for hard work on the DD-WRT firmware.

I tried looking for a solution to reboot the router using Cron on the TP-Link TL-WDR4300. I am on DD-WRT v3.0-r50500 std (10/13/22). Scheduled reboot under 'Keep Alive' works as expected. However, I was experimenting with restarting the router twice a week using Cron, instead of restarting everyday. I followed the instructions at https://wiki.dd-wrt.com/wiki/index.php/Scheduled_reboot

Steps I followed are:

1. Disabled 'Scheduled Reboot' under Administration -> Keep Alive
2. Enabled Cron under Administration -> Management.
3. Pasted the following code in the 'Additional jobs' textbox:
Code:
echo "startservice run_rc_shutdown; /sbin/reboot" > /tmp/restart_router
chmod a+x /tmp/restart_router
echo "0 3 * * 2,5 root /tmp/restart_router" > /tmp/cron.d/restartrouter

4. I want to restart the router at 3 AM every Tuesday and Friday.
5. I saved and applied settings. Even rebooted the router.
6. I do see the 'cron' process running when I run the 'top' command in telnet.

The router does not restart, nor do I see any attempt to reboot the router in syslog.

Tried this on another router, TP-Link TL-WDR3500, with same results. I tried searching the forums for similar issue, but did not find any topics.

What am I missing?

Regards,
-Pranav.


Last edited by cyberpranav on Tue Nov 15, 2022 23:08; edited 2 times in total
Sponsor
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1899

PostPosted: Wed Nov 02, 2022 3:09    Post subject: Reply with quote
"Additional cron jobs" are entered as a crontab, not a script; the reference clearly states to put that in Administration -> Commands and save as startup.
cyberpranav
DD-WRT Novice


Joined: 01 Jan 2019
Posts: 20

PostPosted: Wed Nov 02, 2022 5:48    Post subject: Oh man. :-( Reply with quote
Hi dale_gribble39.

I am feeling sheepish right now. Sad

Thanks for pointing out the correct place. I really don't know how I missed the reference, which is in bold. Crying or Very sad

I'll try this out. Thank you!

Regards,
-Pranav.
the-joker
DD-WRT Developer/Maintainer


Joined: 31 Jul 2021
Posts: 2146
Location: All over YOUR webs

PostPosted: Wed Nov 02, 2022 10:38    Post subject: Reply with quote
Ive suggested a web interface enhancement to support everyday/single day/multiple days like we already do in access restrictions. Would be far more useful/flexible imo.

No promises.



Capture.PNG
 Description:
 Filesize:  3.35 KB
 Viewed:  1621 Time(s)

Capture.PNG



_________________
Saving your retinas from the burn!🔥
DD-WRT Inspired themes for routers
DD-WRT Inspired themes for the phpBB Forum
DD-WRT Inspired themes for the SVN Trac & FTP site
Join in for a chat @ #style_it_themes_public:matrix.org or #style_it_themes:discord

DD-WRT UI Themes Bug Reporting and Discussion thread

Router: ANus RT-AC68U E1 (recognized as C1)
cyberpranav
DD-WRT Novice


Joined: 01 Jan 2019
Posts: 20

PostPosted: Wed Nov 02, 2022 20:40    Post subject: This would be awesome! Reply with quote
the-joker wrote:
Ive suggested a web interface enhancement to support everyday/single day/multiple days like we already do in access restrictions. Would be far more useful/flexible imo.

No promises.


This enhancement would be awesome!

Thanks for the information the-joker.

Regards,
-Pranav.
cyberpranav
DD-WRT Novice


Joined: 01 Jan 2019
Posts: 20

PostPosted: Tue Nov 15, 2022 23:06    Post subject: Router does not reboot. Reply with quote
Hi team.

Seems like I am making some other mistake which is preventing the router from rebooting. Attached is how the current startup code looks like. I tried changing the job to restart everyday, instead of Tuesday and Friday, but still does not work.

What am I doing wrong?

Thanks!
-Pranav.



DDWRT_Restart.png
 Description:
 Filesize:  29.34 KB
 Viewed:  1519 Time(s)

DDWRT_Restart.png


mwchang
DD-WRT Guru


Joined: 26 Mar 2013
Posts: 1855
Location: Hung Hom, Hong Kong

PostPosted: Wed Nov 16, 2022 12:21    Post subject: Re: Router does not reboot. Reply with quote
cyberpranav wrote:
1. Disabled 'Scheduled Reboot' under Administration -> Keep Alive
2. Enabled Cron under Administration -> Management.
3. Pasted the following code in the 'Additional jobs' textbox:
Code:
echo "startservice run_rc_shutdown; /sbin/reboot" > /tmp/restart_router
chmod a+x /tmp/restart_router
echo "0 3 * * 2,5 root /tmp/restart_router" > /tmp/cron.d/restartrouter

4. I want to restart the router at 3 AM every Tuesday and Friday.
5. I saved and applied settings. Even rebooted the router.
6. I do see the 'cron' process running when I run the 'top' command in telnet.

The router does not restart, nor do I see any attempt to reboot the router in syslog.

cyberpranav wrote:
Hi team.

Seems like I am making some other mistake which is preventing the router from rebooting. Attached is how the current startup code looks like. I tried changing the job to restart everyday, instead of Tuesday and Friday, but still does not work.

You sure that Cron is running? Run `ps | grep -i cron` to check.
Also, test run your /tmp/restart_router in a shell to make sure that it has no error.
You don't have to use "chmod a+x", just call it by "/bin/sh restart_router" in the cron entry!
But if you insist, make sure that the first line of restart_router is "#!/bin/sh"!

BTW, you can use the logger command to write an entry into /var/log/messages!
Code:
/usr/bin/logger "restart_router[$$]: started"

I remember some differences between system cron entry (/etc/crontab) and user ones... might not be relevant. But DD-WRT is not a standard Linux distribution.


Might be helpful:

DD-WRT :: View topic - cron job - how?
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=308836&sid=dd0703806c7b8c8056a5e15a2acae3b4

dd-wrt cron - Google Search
https://www.google.com/search?client=firefox-b-d&q=dd-wrt+cron+

_________________
Router: Asus RT-N18U (rev. A1)

Drink, Blink, Stretch! Live long and prosper! May the Force and farces be with you!

Facebook: https://www.facebook.com/changmanwai
Website: https://sites.google.com/site/changmw
SETI@Home profile: http://setiathome.berkeley.edu/view_profile.php?userid=211832
GitHub: https://github.com/changmw/changmw
cyberpranav
DD-WRT Novice


Joined: 01 Jan 2019
Posts: 20

PostPosted: Thu Nov 17, 2022 22:09    Post subject: Re: Router does not reboot. Reply with quote
mwchang wrote:
cyberpranav wrote:
1. Disabled 'Scheduled Reboot' under Administration -> Keep Alive
2. Enabled Cron under Administration -> Management.
3. Pasted the following code in the 'Additional jobs' textbox:
Code:
echo "startservice run_rc_shutdown; /sbin/reboot" > /tmp/restart_router
chmod a+x /tmp/restart_router
echo "0 3 * * 2,5 root /tmp/restart_router" > /tmp/cron.d/restartrouter

4. I want to restart the router at 3 AM every Tuesday and Friday.
5. I saved and applied settings. Even rebooted the router.
6. I do see the 'cron' process running when I run the 'top' command in telnet.

The router does not restart, nor do I see any attempt to reboot the router in syslog.

cyberpranav wrote:
Hi team.

Seems like I am making some other mistake which is preventing the router from rebooting. Attached is how the current startup code looks like. I tried changing the job to restart everyday, instead of Tuesday and Friday, but still does not work.

You sure that Cron is running? Run `ps | grep -i cron` to check.
Also, test run your /tmp/restart_router in a shell to make sure that it has no error.
You don't have to use "chmod a+x", just call it by "/bin/sh restart_router" in the cron entry!
But if you insist, make sure that the first line of restart_router is "#!/bin/sh"!

BTW, you can use the logger command to write an entry into /var/log/messages!
Code:
/usr/bin/logger "restart_router[$$]: started"

I remember some differences between system cron entry (/etc/crontab) and user ones... might not be relevant. But DD-WRT is not a standard Linux distribution.


Might be helpful:

DD-WRT :: View topic - cron job - how?
https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=308836&sid=dd0703806c7b8c8056a5e15a2acae3b4

dd-wrt cron - Google Search
https://www.google.com/search?client=firefox-b-d&q=dd-wrt+cron+


Thank you for the detailed response mwchang. I 'll definitely check and respond when I check these out.

Thanks!
-Pranav.
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 371

PostPosted: Tue Nov 22, 2022 2:54    Post subject: Re: Scheduled reboot using Cron not working. Reply with quote
cyberpranav wrote:
Scheduled reboot under 'Keep Alive' works as expected. However, I was experimenting with restarting the router twice a week using Cron, instead of restarting everyday.

Since 'Keep Alive' works as expected you know cron is working. Just pick Tuesday in the GUI instead of Everyday (Save & Apply) and you're half way there. You can see the cron job dd-wrt created with:
Code:
cat /tmp/cron.d/check_schedules

Then in a startup command, echo the output of the above command to a different file like (check_schedules2) but change the 02 to 05 and you have your Friday reboots.
Code:
echo "0 3 * * 05 root /sbin/service run_rc_shutdown start; /sbin/reboot" > /tmp/cron.d/check_schedules2

Another solution would be to set the nvram variable schedule_weekdays to 02,05 at the command-line. The GUI doesn't allow selecting multiple days but the underlying code seems to support it. The problem is, any later saving of 'Keep Alive' in the GUI will overwrite schedule_weekdays losing your two day hack.
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1899

PostPosted: Tue Nov 22, 2022 15:42    Post subject: Reply with quote
Or put this in the "Additional Cron Jobs" input textbox and save after removing the third line from the startup script:

Code:
0 3 * * 2,5 root /tmp/restart_router

Which is what I was suggesting in the first place.

_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
yoyoma2
DD-WRT User


Joined: 24 Sep 2016
Posts: 371

PostPosted: Tue Nov 22, 2022 23:09    Post subject: Reply with quote
The point is that generating restart_router is useless. If he wants to disable dd-wrt's Keep Alive->Schedule Reboot completely, then sure this additional cron job alone can do the trick instead of solutions given earlier (same difference).
Code:
0 3 * * 2,5 root /sbin/service run_rc_shutdown start; /sbin/reboot

No generating restart_router at all.
dale_gribble39
DD-WRT Guru


Joined: 11 Jun 2022
Posts: 1899

PostPosted: Tue Nov 22, 2022 23:40    Post subject: Reply with quote
Correct, I was refraining from stating the obvious because people get a little offended by that.
_________________
"The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep." - Robert Frost

"I am one of the noticeable ones - notice me" - Dale Frances McKenzie Bozzio

<fact>code knows no gender</fact>

This is me, knowing I've ruffled your feathers, and not giving a ****
Some people are still hard-headed.

--------------------------------------
Mac Pro (Mid 2012) - Two 2.4GHz 6-Core Intel Xeon E5645 processors 64GB 1333MHz DDR3 ECC SDRAM OpenSUSE Leap 15.5
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum