Linux Tutorial Step 4 Create and run a script
From ALICE Documentation
Step 4 -- Create and run a script
Before we create a batch script and submit it to a compute node, we will do something a bit simpler. We will create a regular script file that will be run on the login node. A script is just a file that consists of UNIX commands that will run when you execute the script file. It is a way of gathering together a bunch of commands that you want to execute all at once. You can do some very powerful things with scripting to automate tasks that are tedious to do by hand, but we are just going to create a script that contains a few commands we could easily type in. This is to help you understand what is happening when you submit a batch script to run on a compute node.
Use a text editor to create a file named "tutorial.sh" which contains the following text (note that with emacs or nano you can use the mouse to select text and then paste it into the editor with the middle mouse button):
$ nano tutorial.sh echo ---- echo Job started at `date` echo ---- echo This job is working on node `hostname` SH_WORKDIR=`pwd` echo working directory is $SH_WORKDIR echo ---- echo The contents of $SH_WORKDIR ls -ltr echo echo ---- echo echo creating a file in SH_WORKDIR whoami > whoami-sh-workdir SH_TMPDIR=${SH_WORKDIR}/sh-temp mkdir $SH_TMPDIR cd $SH_TMPDIR echo ---- echo TMPDIR IS `pwd` echo ---- echo wait for 12 seconds sleep 12 echo ---- echo creating a file in SH_TMPDIR whoami > whoami-sh-tmpdir # copy the file back to the output subdirectory cp ${SH_TMPDIR}/whoami-sh-tmpdir ${SH_WORKDIR}/output cd $SH_WORKDIR echo ---- echo Job ended at `date`
To run it:
$ chmod u+x tutorial.sh $ ./tutorial.sh
Look at the output created on the screen and the changes in your directory to see what the script did.