Like Progressive Metal? Check out my band on Spotify, please follow us!
We can use Node to run our own shell scripts for creating jobs and utilities to help us manage our linux based servers. This also works on Macs and should work on Windows as well. To get started, you need to install Node on your system, you can start by visiting nodejs.org and following the instructions to install node on your platform.
Installing node is easy on most systems, for instance on ubuntu you will just run the commands:
sudo apt-get install nodejs sudo apt-get install npm
Once node is installed, you can create a simple shell script easily, just make the first line of the file as follows:
In some cases, such as in Ubuntu, the binary is called nodejs instead of just plain node so you will need to change the line to:
Two things you will notice besides the header which we previously discussed. The second line starting with "//" is a comment. Comments are ignored by the interpreter but are very useful when developing large and complex scripts. Everyone forgets what their original logic or intention was when coding a script and it's much easier to read a comment than it is to try to understand large and complex sections of code.
The next thing you will notice is console.log function. This will print text to the console, much line the unix "echo" command. console is an object, which has a function called log which takes a text string as an argument.
Assuming you are running on unix, before we can run this script, we must first make it executable. To do this we will use the unix chmod command:
chmod u+x hello.js
Now our script is executable. This command basically tells unix to set the x (executable) flag for the user level access of the file. Now we are able to run the file. If you don't have "." in your unix PATH environment variable, then you will need to proceed the name of the script with "./" to execute it. It is generally considered to be a security risk to put "." in your PATH evironment variable, so we will assume that you don't have it. Now you can execute your script by using the following command:
Blob Entry 1
Blob Entry 2
Blob Entry 3
Blob Entry 4
Blob Entry 5
Blob Entry 6