|
|
|||
|
||||
Writing batch scripts can range from very simple redirection lists, to rather complicated shell programs. For all these examples it will be assumed you are using a C-shell (csh) for your user environment. You may use other shells if you feel more comfortable with those environments.
We'll start with redirection lists. So far you have seen that you can enter your variables at the GEMPAK command prompt. The CSH language can use files for input instead of the keyboard or other standard input device in a process known as indirection. In this proccess, we say that the input has been redirected from the keyboard to a file. To redirect the GEMPAK prompt input from a file, the CSH syntax would look as follows:
You have seen that at the GEMPAK prompt you can list the values assigned to variables using the list command. If those same lines were redirected from a text file, all those variables would be updated. A file used for redirection simply mimics what you would type. You can use the cut and paste tools in your window environment to save the output from the list command. Often then is very helpful since once you have set up the way you like the variables to be set, you can cut them and paste them into your redirection list.
Many times however, you will need to change variables such as the filename or the dtae/time used. For situation such as this, the standard restore defaults command won't work. You need some way of generating appropriate dates, times, filenames, etc. To do this you will need to use a shell script. You can use shell scripts to ascertain the correct filenames and dates when the program is executed, then ask the shell script to set up the indirection for you.
The Unix environment provides many useful tools which you may want to use to set up various scripts such as automated crontab entries which can execute your scripts at specified intervals. If you aren't familiar will all the Unix toold, or shell environments, you may want to consult on the the many references on the subject.
A word of warning, your scripts must
be able to obtain the appropriate system and environmental resources,
just as if you were running the programs from the user interface.
Lets look at an example of a C-shell script:
#!/bin/csh
source /home/gempak/dist/Gemenviron
set YMD=`date -u '+%y%m%d'`
set SFFILE=$GEMDATA/surface/sao/$YMD.gem
echo -n "Enter the station ID you which to list: "
set STATION=$<
sflist << EOF
SFFILE = $SFFILE
AREA = @${STATION}
DATTIM = all
SFPARM = tmpf;dwpf;pmsl;sped;drct
OUTPUT = t
IDNTYP = stid
r
e
EOF
echo " "
exit(0)
# END of shell script
The shell program above can be copied and pasted into your account. Before you can execute it, you must allow the file to be executed. In Unix, you can use the command chmod a+x filename to allow execution of a file. Try executing the script above (note, you may have to edit the SFFILE location definition, and the location of the Gemenviron file if your locations aren't the same!).
The flag EOF in the script tells the CSH to accept input to the SFLIST command until it sees that flag later in the script. The commands between the two EOF's are used to enter the variables as if you were typing them. The SFFILE and AREA variables are using the value that the CSH variable was assigned in the section preceeding the GEMPAK command.
Why is the blank line required?
Try running SFLIST to see what you type following the run command.
Lets try a few more exercises...
| Contact Us Site Map Search Terms and Conditions Privacy Policy Participation Policy | ||||||
|
||||||