What's new

Persistent Cron Jobs

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Em0ry42

New Around Here
Hi,

I apologize if this has been answered, I searched the forums and Google but didn't seem to find the solution I need:

I have a couple of scripts I would like to run every hour on my ASUS RT-AC66R. As you probably know whenever the router reboots the crontab is removed. So I went to /jffs/scripts and created a file called "services-start" with the following content:

Code:
#!/bin/sh

crontab /tmp/mnt/sda1/scripts/admin

I then made it executable with:

Code:
chmod a+rx /jffs/scripts/services-start

But whenever I try to execute the script I get the following message:

Code:
/jffs/scripts/services-start: line 3: crontab: Permission denied

I've tried several different incantations, all the same result:
Code:
/jffs/scripts/services-start
sh /jffs/scripts/services-start
sh services-start
sh ./services-start

I can run the command via the commandline but it hangs. Ctrl+C breaks out of the hang and the crontab is in place and functioning. The script always returns the error.

I've formatted the JFFS partition via "Administration" and recreated the file, but I've had no luck.

I'm running ASUSWRT-Merlin: 3.0.0.4.374.39_0

For now I don't expect to reboot very frequently but I would prefer to not have to login and replace the crontab any time I do.

Thanks in advance for any help, I greatly appreciate it!
 
Last edited:
Hi,

The correct syntax for adding something to crontab is like this:
Code:
/usr/sbin/cru a RestartWifi " 0 4 * * * /jffs/scripts/restart-wlan.sh"

I am using cru as it's comaptible with older versions of the router firmware as well.

With kind regards
Joe :cool:

PS.: A full view on the crontab syntax can be found in the net...
 
Thanks! This fixed the crontab hanging issue and revealed a new error message:

/usr/sbin/cru: line 4: nvram: Permission denied

A quick Google search revealed I needed to remove bash (not sure how it got installed), but after remove everything works like a dream!

Thanks again!
 
Sorry, but I don't think I fully understand.
I have a RT-AC66R with 3.0.0.4.374.40_0

I want to create a cronjob that visit this page to update my DynDNS:
http://www.domain.com/dyndns/index.php?domain=home.domain.com&password=XXXXX

Can I get some help?
I do have the JFFS and SSH access enabled.

I think I have to write something like this on the cronjob (to get ir run every morning at 4AM):
Code:
0 4 * * * [b]php[/b] http://www.domain.com/dyndns/index.php?domain=home.domain.com&password=XXXXX

So I type this whole line:
Code:
/usr/sbin/cru a RestartWifi " 0 4 * * * [b]php[/b] http://ww
w.xxxx.com/dyndns/index.php?domain=home.xxxx.com&password=XXXX"

How do I tell the router to run the php?
Will that be persistent?
Will that work?

Thanks!
 
Last edited:
The router doesn't have PHP.
 
The router doesn't have PHP.

Yes, that's what I figured out.
Thank you for the confirmation.

But, how can I make the router "load" this page in the background?
I just need the router to requerst that page so my DreamHost webserver get's the router IP and updates my "Dynamic DNS".

Any ideas?
Thanks! Thanks in advance.
 
Yes, that's what I figured out.

Thank you for the confirmation.



But, how can I make the router "load" this page in the background?

I just need the router to requerst that page so my DreamHost webserver get's the router IP and updates my "Dynamic DNS".



Any ideas?

Thanks! Thanks in advance.


Use curl. And put the cru command in an init-start script.
 
Use curl. And put the cru command in an init-start script.

Thanks for the idea, but I don't find curl installed on my router.
Where is it?
 
Also was getting Permission denied error with custom script but after moving the command to init-start and changing command to /usr/sbin/cru a all went fine.
BTW, is there any inline syntax for adding a job via crontab? Alike

Code:
crontab -a " 0 4 * * * /jffs/scripts/restart-wlan.sh"

or the only way is

Code:
/usr/sbin/cru a Wlan " 0 4 * * * /jffs/scripts/restart-wlan.sh"
 
BTW, is there any inline syntax for adding a job via crontab?
No, you have to use cru (or manipulate the crontab file directly which is what cru does).

Code:
# crontab
BusyBox v1.25.1 (2018-04-24 05:02:17 MST) multi-call binary.

Usage: crontab [-c DIR] [-u USER] [-ler]|[FILE]

        -c      Crontab directory
        -u      User
        -l      List crontab
        -e      Edit crontab
        -r      Delete crontab
        FILE    Replace crontab by FILE ('-': stdin)
 
"crontab -e" means "Edit crontab" (not "add"), so it's an interactive operation not a scriptable one.

If you want to add or remove crontab entries from a script use cru, that's why Merlin wrote it.
 
What I did was create a script called interestingly enough 'script_scheduler' which adds all my entires. That script is then called via init-start. I can edit all of my script scheduling without mucking about in some of the more important ones. Less chance of error on my part. :( I am after all still learning and subject to breaking things.

Code:
#!/bin/sh

# ChkWAN status every 15 min & reboot router if needed @ Martineau
cru a ChkWAN "*/15 * * * * sh /jffs/scripts/ChkWAN"

# dnsomatic updater @ Wiki w/ changes by me
cru a dnsomatic "*/60 */24 * * * sh /jffs/scripts/dnsomatic"

# Lights off @  2300 hours @ Wiki
cru a lightsoff "0 23 * * * sh /jffs/scripts/ledcontrol -off"

# Lights on @  0600 hours @ Wiki
cru a lightson "0 6 * * * sh /jffs/scripts/ledcontrol -on"

# Reboot @ 0400 hours @ Wiki
cru a ScheduledReboot "0 4 * * * /sbin/reboot"


# Individual Script additions : 

## 'wan_connect_notification' @thelonelycoder 
### added to 'wan-start' Sends notification when WAN change detected. 
### Disable the above when trying dual-wan-helper

##  'YazFi' @ Jack Yaz 
### added to 'firewall-start' Enhanced wifi for guest networks
### YazFi crontab support to arrive in a future update.

init-start contains only one entry by me.

Code:
sh /jffs/scripts/script_scheduler &
 
Yeah, you could.
I figure most of it is my just being a stickler. Either way as long as it works for your work flow, I know of no benefit to either way, but as I said I am still learning. Who knows what Ill find next week.
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top