*New 11.3 series Release:
2019-10-19: XigmaNAS 11.3.0.4.7014 - released

*New 12.0 series Release:
2019-10-05: XigmaNAS 12.0.0.4.6928 - released!

*New 11.2 series Release:
2019-09-23: XigmaNAS 11.2.0.4.6881 - released!

We really need "Your" help on XigmaNAS https://translations.launchpad.net/xigmanas translations. Please help today!

Producing and hosting XigmaNAS costs money. Please consider donating for our project so that we can continue to offer you the best.
We need your support! eg: PAYPAL

XigmaNAS Scripting Primer / ReadMe!

XigmaNAS Scripts and shell tips
Forum rules
Set-Up GuideFAQsForum Rules
Locked
al562
Advanced User
Advanced User
Posts: 221
Joined: 12 Dec 2012 08:02
Location: New Jersey, U.S.A.
Contact:
Status: Offline

XigmaNAS Scripting Primer / ReadMe!

#1

Post by al562 » 01 Mar 2013 20:39

Q: Do I need to read / understand scripting to use XigmaNAS?
A:
No. The main idea behind XigmaNAS is to provide the end user with a very complex WebGUI (Web based Graphical User Interface) that makes it possible for him / her to easily manage the server without having to know / learn much about the technicalities of the underlying system.

Q: What is the XigmaNAS WebGUI (Web based Graphical User Interface)?
A:
The XigmaNAS WebGUI is a combination of php, java and sh scripts that present a simple way to take end-user input and process the commands via shell and / or other Unix utility ( programs ).

Q: What is a / the Shell?
A:
A special program that accepts your instructions or commands in English ( mostly ) and if it's a valid command will translate your command into machine language then pass the instructions to the OS kernel for processing. The shell is similar to the DOS prompt in Windows and is also frequently referred to as a CLI ( Command Line Interpreter or Interface ).

Q: Who will ever want to get complicated and use shell commands and / or shell scripts? Why would someone ever be interested in writing a script?
A:
Users who want to go beyond the inherent limits of the WebGUI or who need / want to do things the developers did not envision / think to include / have not had time to include / figure out.

Q: Why does the WebGUI have limits?
A:
No matter how complex / big the XigmaNAS WebGUI becomes, it will be almost impossible to control all aspects of the XigmaNAS OS from it. Remember too that one of the other major goals of the project is to keep everything small so XigmaNAS will run on almost any hardware / require the least amount of resources possible. Therefore it will not always be possible / convenient / smart / popular to try to control / configure some things from the WebGIUI

Q: What shell(s) are included in XigmaNAS?
A:
XigmaNAS includes: *Note: Each shell does a similar job, but each understands a slightly different command syntax and provides different built-in functions. Some shells are better for some things than others. It is very much a matter of preference / experience that will lead you to choose one shell over another. If you are not sure or have little experience stick the most frequently used shell - sh. If you desire to learn more please read Comparison of command shells.

Q: How can I create / run a basic script from the WebGUI?
A:
Follow these steps:
  1. Create an empty file from WebGUI Tab> Advanced|Execute Command ( in this example /mnt/mount/my_script.sh ).

    Code: Select all

    touch /mnt/mount/my_script.sh
  2. Set execute permission for owner ( you ) only, from WebGUI Tab> Advanced|Execute Command.

    Code: Select all

    chmod u+x /mnt/mount/my_script.sh
  3. Edit your empty file ( script ) from WebGUI Tab> Advanced|File Editor. Type the following script, or just copy/paste

    Code: Select all

    #!/bin/sh
    /bin/echo "Hello World!"
  4. Save the script ( click Save ).
  5. Run the script from WebGUI Tab> Advanced|Execute Command.

    Code: Select all

    /mnt/mount/my_script.sh
The output should be:

Code: Select all

$ /mnt/mount/my_script.sh
Hello World!
Q: Where should I save my scripts?
A:
The simple answer is wherever it's convenient, but different people have different needs. Depending on the XigmaNAS platform you are running and other, special, circumstances some places are better than others, this is explained in Where can I save my scripts?

Q: How to get script to run automatically, on schedule?
A:
You can create a "cron" (Unix task scheduler) job in WebGUI Tab> System > Advanced > Cron. Always use the full path to your scriptscript, e.g.: /mnt/mount/my_script.sh.

Q: How come my script works in shell when invoked manually but not in CRON?
A: In XigmaNAS, CRON does not have a user profile set. When you run a script or command manually it runs using your user profile / settings / privileges, (root usually). CRONs' settings / privileges are not the same as roots'. To make sure your script / command works properly you need to fully specify all path names and ensure non-root access to files, folders and processes. You can also set a profile for CRON with root credentials, but this is not recommended for security reasons. There are many examples / explanations about getting scripts and commands to run in Q: How come my script works in shell when invoked manually but not in CRON? and this is where you should start troubleshooting if you are having a problem running a script or command.

This is an updated / revised version of the "Shell Scripting FAQ" from the old Forum!

Locked

Return to “Scripts and shell tips”