× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

Best scripting practices?

leoj3n
Aspirant

Best scripting practices?

Is there some way to stop this from happening in the future? Is there such a thing as best scripting practices? I haven't done much bash scripting... Is it safe to use "mv" and "ls" and "rm" in a bash script? What's the safest way?

Is there a way to "limit the permissions" of a bash script?
Message 1 of 5
mdgm-ntgr
NETGEAR Employee Retired

Re: Best scripting practices?

Bash scripts do have to be written properly. You can do serious damage e.g. even wipe out all the data on the NAS with the wrong commands issued in the wrong places.

The `ls` command is definitely safe to use. It doesn't make any modification. It just lists the content of one/more directories (depending on what options you use).

As for mv and rm so long as you write the script properly they will be fine to use too (though it is best to experiment on a non-production system that is backed up). But if you were to do e.g.

rm -rf /*

you better have a good backup to restore from if you want your data back.

So you do need to take some care that you define the directories you're using and if you want to wipe the contents of a directory specify that when you issue the rm command just to be safe.
e.g.

rm -rf /c/media/mydirectorytodelete

Of course you can use variables to simplify the script as you have done.

and you can use 'pwd' to check the current working directory and the 'cd' command to change the working directory.

Some good example scripts to look at would be the install.sh scripts for add-ons. Community add-ons are easy to unpack.

To limit the permissions of a bash script you'd need to get it to be run by a user with limited permissions not root. Though this also comes with its own disadvantages.


May I suggest you install Virtualbox (free VM app) and install a Ubuntu/Debian VM and do some experimenting in that? Most of the commands are going to be similar to/the same as what you'd use on the ReadyNAS. If you mess up the VM you can revert to a snapshot or create a new one and do some more experimenting.
Message 2 of 5
leoj3n
Aspirant

Re: Best scripting practices?

I will try the virtual machine. I should be able to replicate the NAS file structure in a test environment for testing the filesystem modifications in my script.
Message 3 of 5
leoj3n
Aspirant

Re: Best scripting practices?

In fact, Is it possible to mount a ReadyNAS image in VM?
Message 4 of 5
mdgm-ntgr
NETGEAR Employee Retired

Re: Best scripting practices?

No. The firmware will only run on the ReadyNAS
Message 5 of 5
Top Contributors
Discussion stats
  • 4 replies
  • 3056 views
  • 0 kudos
  • 2 in conversation
Announcements