Bash script survives firmware upgrades

Post new topic   Reply to topic    DD-WRT Forum Index -> Ralink SoC based Hardware
Author Message
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Fri Feb 12, 2016 9:16    Post subject: Bash script survives firmware upgrades Reply with quote
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?
Sponsor
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Sun Feb 14, 2016 11:30    Post subject: Re: Bash script survives firmware upgrades Reply with quote
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?


No one?
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Mon Feb 22, 2016 14:34    Post subject: Reply with quote
eibgrad wrote:
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...
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Mon Feb 22, 2016 20:01    Post subject: Reply with quote
eibgrad wrote:
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?

Code:
SCRIPT="/tmp/root/wol.sh"
cat << "EOF" > $SCRIPT
wol.sh
EOF
chmod +x $SCRIPT
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Mon Feb 22, 2016 21:16    Post subject: Reply with quote
eibgrad wrote:
Not quite. The purpose of the code I gave you is to create the file wol.sh. But you just made it self-referencing, which doesn't accomplish anything.

Suppose I wanted to create a file called wol.sh that contained the following code.

Code:
#!/bin/sh
/usr/sbin/wol -i 192.168.1.255 -p 7 00:11:22:33:44:55


I can create that file under /tmp/root as follows.

Code:
SCRIPT="/tmp/root/wol.sh"
cat << "EOF" > $SCRIPT
#!/bin/sh
/usr/sbin/wol -i 192.168.1.255 -p 7 00:11:22:33:44:55
EOF
chmod +x $SCRIPT


If you add this to the startup script, you'll find that script (wol.sh) there and ready to execute after every reboot.


Thanks, I'll try that tomorrow.
This code has to go in the startup shell right?
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Tue Feb 23, 2016 9:09    Post subject: Reply with quote
eibgrad wrote:
startup script (Administration->Commands, enter script, hit Save Startup)


Will it stick after firmware upgrade through web?
CounterC
DD-WRT Novice


Joined: 05 Nov 2015
Posts: 40

PostPosted: Wed Feb 24, 2016 7:51    Post subject: Reply with quote
eibgrad wrote:
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?
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Ralink SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum