GRASS and Shell: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(remove session tmp directory)
(clarified .grassrc6 ; parallel GRASS jobs)
Line 10: Line 10:
   export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
   export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib
  # path to GRASS settings file (better generate this file on the fly):
  export GISRC=$HOME/.grassrc6
   
   
   # use process ID (PID) as lock file number:
   # use process ID (PID) as lock file number:
Line 22: Line 19:
   export GRASS_WIDTH=900
   export GRASS_WIDTH=900
   export GRASS_PNG_COMPRESSION=1
   export GRASS_PNG_COMPRESSION=1
The following variable defines where the GRASS settings file is stored. This can be anywhere on the system. You could also generate the '.grassrc6' on the fly in your script, even with different name. Just indicate it correctly:
  # path to GRASS settings file
  export GISRC=$HOME/.grassrc6


Now you can test:
Now you can test:
Line 42: Line 45:


* GRASS shell script job to generate a [http://grass.itc.it/spearfish/grass_earthquakes.sh Recent Earthquakes Map]
* GRASS shell script job to generate a [http://grass.itc.it/spearfish/grass_earthquakes.sh Recent Earthquakes Map]
=== Parallel GRASS jobs ===
If you want to lauch several GRASS jobs in parallel, you have to launch each job in its own mapset. Be sure to indicate the mapset correctly in the GISRC file (see above). You can use the process ID (PID, get with $$) to generate a almost unique number which you can add to the mapset name.


=== See also ===
=== See also ===

Revision as of 16:25, 6 July 2006

It is fairly easy to write a GRASS job as Shell script which launches GRASS, does the operation and cleans up the temporary files.

You have to set a couple of variables to enable GRASS command to run:

  # Example in bash shell syntax:

  # path to GRASS binaries and libraries:
  export GISBASE=/usr/local/grass60

  export PATH=$PATH:$GISBASE/bin:$GISBASE/scripts
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GISBASE/lib

  # use process ID (PID) as lock file number:
  export GIS_LOCK=$$

  # settings for graphical output to PNG file (optional)
  export GRASS_PNGFILE=/tmp/grass6output.png
  export GRASS_TRUECOLOR=TRUE
  export GRASS_WIDTH=900
  export GRASS_PNG_COMPRESSION=1


The following variable defines where the GRASS settings file is stored. This can be anywhere on the system. You could also generate the '.grassrc6' on the fly in your script, even with different name. Just indicate it correctly:

  # path to GRASS settings file
  export GISRC=$HOME/.grassrc6

Now you can test:

  # this should print the GRASS version used:
  g.version
  # other calculations go here ...

You should cleanup internal tmp files like this:

  # run GRASS' cleanup routine
  $GISBASE/etc/clean_temp

  # remove session tmp directory:
  rm -rf /tmp/grass6-$USER-$GIS_LOCK

If this works, you can launch other GRASS commands. The approach works within Shell scripts and also in the command line terminal.

Example

Parallel GRASS jobs

If you want to lauch several GRASS jobs in parallel, you have to launch each job in its own mapset. Be sure to indicate the mapset correctly in the GISRC file (see above). You can use the process ID (PID, get with $$) to generate a almost unique number which you can add to the mapset name.

See also