First, let's write our shell script. This script does the following:
- Print the value of the environment variable, MY_VARIABLE.
- Execute the tree command.
- Execute the iostat command.
Let's create a shell script file by the name, script.sh, with the following commands in it:
echo $MY_VARIABLE; echo "Running tree command"; tree; echo "Running iostat command" iostat;
You can place the script.sh in your home folder that is, in the /home/<username>. Now let's see how we can execute this from Java.