1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding a retained in memory CronTab to reboot?

Discussion in 'HyperWRT Firmware' started by grymwulf, Nov 5, 2004.

  1. grymwulf

    grymwulf Network Guru Member

    I seem to have a problem if my router is running continously for over a day- 2 days.

    (Lots of p2p activity)

    Is there a way to set up a crontab that automatically reboots the router everyday at say.... 5 am?

    And this crontab stays in memory through the reboot to do this automatically with no user intervention for weeks at a time?
  2. Toxic

    Toxic Administrator Staff Member

    i dont know as yet how to do this in hyperwrt but this may help. it was extracted from sveasoft forums for alchemy.

    try to use this as the basis for hyperwrt.
  3. grymwulf

    grymwulf Network Guru Member

  4. Toxic

    Toxic Administrator Staff Member

    echo "00 04 * * * root /sbin/reboot" > /tmp/crontab

    the 00 04 means 4:20am

    55 05 means 5:55am etc etc
  5. Toxic

    Toxic Administrator Staff Member

    it would seem if you do this command s it overwrites the existng crontab which is:


    dunno how you add both commands to the crontab but perhaps someone will know
  6. grymwulf

    grymwulf Network Guru Member

    Ummm oooops then....

    gonna go fix that....
  7. chamiz

    chamiz Network Guru Member

    Is there a code for every other days?
  8. grymwulf

    grymwulf Network Guru Member

    Yes there is, ummm 1 sec while I pull up linky....

    It looks like you can do it once per week, not sure of every other day.
    From: http://www.nerc-online.com/support/www/crontab.html

    What is Crontab?
    Crontab is a program that allows users to create jobs that will run at a given time. Each individual user has their own crontab and the entire system has a crontab that can only be modified by those with root access. If you are adding a crontab for an individual user you must sign on as that user first. (ex. su userid)

    The syntax of this file is very rigid. There are six fields to a file, each separated by a space. The first five fields specify exactly when the command is to be run; the sixth field is the command itself. The first five fields are:

    minute hour day month weekday command
    Minute - Minutes after the hour (0-59).
    Hour - 24-hour format (0-23).
    Day - Day of the month (1-31).
    Month - Month of the year (1-12).
    Weekday - Day of the week. (0-6; the 0 refers to Sunday).

    Asterisks (*) specify when commands are to be run in every instance of the value of the field. For instance, an asterisk in the Month field would mean that the command should be run every month. In addition, multiple events can be scheduled within a field by separating all instances with commas - with no space between.
  9. dankim831

    dankim831 Network Guru Member

    i finally figured out how to make retained after reboot crontabs properly.

    i've discovered that just over writing the crontabs file is apparantly a bad thing to do.

    so heres what to do:

    Rebooting via cron at 4:00am daily -

    1. log into web interface
    2. click administration
    3. click diagnostics
    4. paste the following in the commands window

    /bin/sleep 20
    /bin/echo "0 4 * * * /sbin/reboot" >> /tmp/upnpcron
    /usr/bin/crontab /tmp/upnpcron

    6. click save startup
    7. reboot

    to check if this worked you can telnet into your router and check your cron table with this command

    crontab -l <---- lowercase L

    you should see 0 4 * * * /sbin/reboot show up.

    crontab is the linux interface for modifying crontabs.

    hope this helped out a lot.
  10. Dave123abc

    Dave123abc Network Guru Member

    The Linux command to write to a file is ">".
    The Linux command to append to a file is ">>".
  11. Dave77459

    Dave77459 Network Guru Member

    I can't find crontab except in the /tmp directory, and it isn't executable. Does the /tmp/upnpcron file have some special meaning that cron will understand?

    If you can't tell, I am only tangentially aware of how Linux works.
  12. Dave77459

    Dave77459 Network Guru Member

    After endless monkeying, this seems to work... I place this in the Startup Script on "Firmware Version: v3.01.3 - HyperWRT 2.0b3":

    /bin/sleep 20
    /bin/echo "00 12,13 * * * root /sbin/reboot" >> /tmp/crontab
    /bin/echo "15,30 13,20 * * * root /sbin/reboot" >> /tmp/crontab

    /tmp/crontab seems to be created each time from some image, so I can just append to it.

    I am rebooting frequently now to test. I create a telnet link and when I reboot the connection is lost. I have an access restriction so that the kids' computer loses internet access at 10:00. However, it seems that existing connections remain unless the router is rebooted. Having this auto-reboot will be a Good Thing.

    I hope rebooting doesn't damage the router.
  13. sillygoose

    sillygoose Network Guru Member

    If the problem you are trying to addess is that the router doesn't drop existing connections based on parental control rules. Instead of rebooting the router you might trying taking the interface down and bringing it back up using the ifconfig command instead of rebooting.

Share This Page