Posted: Fri Feb 12, 2016 9:16 Post subject: Bash script survives firmware upgrades
Hi,
I have an extremeley simple Bash script in the ~ folder of my DD-WRT router to wake up my Desktop PC remotely (SSH).
When I do firmware upgrades (quite often), the Bash script is removed.
Where do I have to place it so it will survive firmware upgrades?
Posted: Sun Feb 14, 2016 11:30 Post subject: Re: Bash script survives firmware upgrades
CounterC wrote:
Hi,
I have an extremeley simple Bash script in the ~ folder of my DD-WRT router to wake up my Desktop PC remotely (SSH).
When I do firmware upgrades (quite often), the Bash script is removed.
Where do I have to place it so it will survive firmware upgrades?
Since nothing persists in the home folder (~), even on a reboot much less a firmware update, you must be creating this script in the startup script. And like anything stored in the router's various scripts (startup, firewall, etc.), these need to be stored OFF the router for safe keeping. And not just because of firmware updates, but in case you ever have to reset a hung router.
Personally I don't think it's a good idea to EVER do a firmware update without doing a complete reset of nvram (where your script would normally be stored). To do otherwise is to ask for trouble. If that means having to copy/paste your scripts after each firmware update, it seems a small price to pay for having the router is known, good state.
Thanks for answering.
I agree with your option to reinstall the script everytime I do firmware upgrade, it's not that big of a deal, I was only wondering.
Another question:
Is there a folder I can place a sh script in that survives after reboot?
Currently I have a sh script in /tmp/root but every time I turn off the router it dissapears because it's a temporary directory. Copying to root (/) dir doesn't seem to work as root...
The router is designed to be fully recoverable. It stores everything in nvram and upon reboot, maps the entire filesystem into memory and uses nvram to reinitialize various settings and variables. That's why nothing is saved from folders. You're always working w/ what is in effect a RAM drive.
What most ppl do is use the startup script to create (or more precisely, recreate) their scripts.
Code:
SCRIPT="/tmp/myscript.sh"
cat << "EOF" > $SCRIPT
### your script goes here ###
EOF
chmod +x $SCRIPT
Yes, a bit of a pain, but it has the desired effect.
The only way to have a persistent folder and set of files in the traditional sense (short of USB and external storage) is to use jffs. A portion of nvram is set aside for the /jffs filesystem. And is mounted to the /jffs folder on every reboot. You just have to be careful not to use jffs for anything that writes too often since nvram has a limited number of write-cycles. A lot more than you'll typically need. But if you do something dumb, like place a log file there, then it's possible you could prematurely wear out nvram.
Thanks, so my script is called wol.sh then it becomes?
If you go to Administration->Firmware Upgrade, it offers the option to NOT reset to defaults. I assume this is supposed to preserve nvram (and by extension, your scripts). But I never use that option, and so I don't know if it works. And I don't use it because it makes no sense (to me anyway) to be doing a firmware upgrade w/ the assumption that the prior settings will still work. In fact, we often see artifacts left behind from the firmware upgrade process that cause all kinds of weird problems. It's just good practice to always do a factory reset AFTER a firmware upgrade to eliminate these artifacts. And once you do, all your scripts are gone and must be reinstalled.
So bottom line, assume your scripts will never survive a firmware upgrade and that you'll have to reinstall them.
I see now.
Actually I never do full reset when updating firmware because I have so many custom settings that it's difficult to manage. Do you have a comfortable way of doing this?