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

Scheduler question

Discussion in 'Tomato Firmware' started by eegorr, May 28, 2009.

  1. eegorr

    eegorr Network Guru Member

    Before anyone asks, I already searched the forum for the answer to my question. LOL!

    I need to run a script hourly, but, more specifically, at the top of the hour, like 4:00AM, then 5:00AM, etc. I have been able to accomplish this manually by first setting the script to run on the next hour, then changing the schedule to hourly via the GUI after it runs the first time. By running once on the hour, "sch_c1_last" (in NVRAM) is set appropriately, then this is used as the basis for determining the next time that the script will run. The values of sch_c1_last, sch_c2_last, and sch_c3_last do not survive a reboot - in fact, if you look for them they do not even exist until the script is first run.

    I set up the script to change the schedule in NVRAM to hourly using the following:
    nvram set sch_c1=1,-60,127 # set to run hourly
    but this did not work. I'm guessing that I need to restart cron or something else in order for the change to take effect.

    Even if I got that working, the problem is that I have to do something every time the router is rebooted - schedule it first to run on the next hour, then change the schedule to hourly after the first run. Assuming I can resolve the issue about why the schedule cannot be changed from the script (restarting cron, or whatever), I might be able to accomplish this be creating sch_c1_last in NVRAM and setting it to a value corresponding to the last hour. I would do this in the Init script, before cron is started, I guess, and just leave the scheduler set up to run the script hourly. To do this, I would need to evaluate the current time, detemine the last hour, then calculate a value for sch_c1_last. Is there an easy way to do this?

    Failing that, I guess I could save the value of sch_c1_last to JFFS in the shutdown script, then restore it again in the init script. There are cases where this could give undesired results, though, as when the reboot occurs shortly before the top of the hour.

    Is anyone doing something like this now? Any suggestions?

    Thanks in advance...
  2. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    Add this to your init script
    cru a OnTheHour "0 * * * * /path/to/script"
    And it will run every hour on the hour.
  3. eegorr

    eegorr Network Guru Member

    Thanks. Sounds like I should do this completely outside the GUI, then, right?

    Can I run the script direcly from /jffs or does it need to be copied to RAM first?
  4. SgtPepperKSU

    SgtPepperKSU Network Guru Member

    Yeah, I don't there is a way to have a periodic command run at specific times in the GUI.

    The scripts should run just fine in JFFS.
  5. fyellin

    fyellin LI Guru Member

    I'm not sure what you mean by "completely outside the GUI". SgtPepperKSU's solution was to use the GUI's init section to add something to the cron table using "cru".
    You can pretty much run scripts from anywhere that looks like a file system.
  6. eegorr

    eegorr Network Guru Member

    I meant not using one of the GUI based scheduler scripts, of course, but you probably already knew that. LOL!

Share This Page