What's new

Persistent crontab by linking to /jffs

  • 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!

latenitetech

Regular Contributor
One of my recent projects has been migrating my (old) X10-based home automation solution from a Windows PC (running 'Active Home Vista') to my Asus router (using the Linux program 'heyu'), partly so I can realize electricity savings by not having to run that PC 24x7 (while the router is always on anyway), and also just as an interesting hobby project.

The heyu implementation makes use of cron for scheduling/running local events (all via the 'cru' command in heyu scripts), and I was looking for an easy way to make such events persistent across reboots. Looking around this forum and the web in general, there are lots of posts about just rebuilding crontab on reboot with individual 'cru' entries in init-start, or keep a crontab mirror in jffs, then copy it over to /var/spool/cron/crontabs in init-start. So I considered similar solutions, but those methods are a bit of a pain to keep track of and restore dynamic 'cru' activity.

But then it occurred to me, "Why not just put the actual crontab file in /jffs with a link?" Then whatever changes get made to it on the fly (e.g. via 'cru') would always still be there on reboot. No need to have "rebuild" commands on startup, or keep a mirror. I did some googling on this kind of persistent solution and didn't find much, although admittedly my searching wasn't exhaustive. My apologies if this has already been proposed and discussed previously.

It's actually quite trivial to implement with just a link command added to init-start:
Code:
#first remove firmware-created empty directory prior to link creation
rmdir /tmp/var/spool/cron/crontabs
ln -ns /jffs/crontabs /tmp/var/spool/cron/crontabs

Obviously you need to do a one-time setup of creating /jffs/crontabs, and then copying over the current crontab file (/var/spool/cron/crontabs/admin) to that new directory. To test it first without rebooting, it's best to first stop crond (service stop_crond), then create the link above, then restart crond (service start_crond). Cron should work as expected, and then on reboot as well, with all your previously scheduled jobs just as they were prior to reboot. Of course, if you already have a reboot recovery solution in place (e.g. rebuild cru entries, or a copy mirror), you'd want to disable them.

I've been running with it this way for about a month now, rebooted numerous times, and upgraded fw to 380.65 and it all seems to work fine. Anyone see any fatal flaw in this approach? I know there is always a concern of excessive writing of jffs, but my 'heyu' crontab updates are typically less than a dozen a week, so I don't think that would be considered excessive.

Anyway, just sharing it here for feedback and/or if someone else finds this approach interesting or useful.
 
Hi, looks this method interesting and new to me... I am try to run a simple tcp dump and save it into a file for every 10min - with cru but not successful.
will try your method. hope it will work. Thanks for sharing.

Cheers!
chandra
 
Hi, looks this method interesting and new to me... I am try to run a simple tcp dump and save it into a file for every 10min - with cru but not successful.
will try your method. hope it will work. Thanks for sharing.

Cheers!
chandra
I'm curious how this would help, unless your problem is loosing your 'cru' entries upon reboot. That's all my solution addresses; cru (and all crontab related commands) behave exactly as they always have. All I'm proposing is storing the 'crontab' file (the file that contains the schedule and commands you want to have run by cron) in /jffs so they transparently survive a reboot. (By default, Asuswrt places the crontab file in ram, so it is lost on reboot, requiring other methods to restore or rebuild the crontab.)

I just find the /jffs link solution much cleaner/easier once set up. I can use cru to add/remove/change cron events from the command prompt (or scripts) all I want and never have to worry about loosing them on reboot.

Keep us posted on your progress, and best of luck!

-Mark
 
Dear Mark,
Got your reply. yes, CRU solution much easier. There is some issue on cru last week ,so i trying all the method. I will use cru only. Thanks a lot.

Cheers!
chandra
 
>> so i trying all the method. I will use cru only.
:) There is typo in my previous msg. I tried all the method... found Cru is easy to implement. Already using it with services-start. :cool:

Cheers!
chandra
 

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