[GRASS-dev] Cron in batch processing

Sheeja Bhaskaran vbsheejabhaskar at yahoo.com
Wed May 13 07:23:09 EDT 2009


Respected Sir,

                      My project is batch processing in GRASS GIS.I need to execute the mapset created automatically in every 1hrs.I tried it using sleep,but it is better to use cron is the suggestion.No idea about how to use cron in batch processing.Give me some guideliness of cron with example and reference ,how to use it in batch processing.Batch processing script is below
  #!/bin/sh

# the file contains the GRASS variables which define the LOCATION etc.
echo "GISDBASE=/root/weath
LOCATION_NAME=kerala
MAPSET=temperature
GRASS_DB_ENCODING=utf-8
MONITOR=x2
GRASS_GUI=text"
 


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


##### the algorithms goes here

error_routine () {
 echo "ERROR: $1"
 exit 1
}
echo "  GRASS_BATCH_JOB                shell script to be processed as batch job"
if [ -n "$GRASS_BATCH_JOB" ] ; then
   # defined, but ...
   if [ ! -f "$GRASS_BATCH_JOB" ] ; then
      # wrong file
      echo "Job file '$GRASS_BATCH_JOB' has been defined in the 'GRASS_BATCH_JOB' variable but not found. Exiting."
      echo "Use 'unset GRASS_BATCH_JOB' to disable batch job processing."
      exit 1
   else
      # right file, but ...
      if [ ! -x "$GRASS_BATCH_JOB" ] ; then
         echo "Please change file permission to 'executable' for '$GRASS_BATCH_JOB'"
         exit 1
      else
         echo "Executing '$GRASS_BATCH_JOB' ..."
         SHELL="$GRASS_BATCH_JOB"
      fi
   fi
fi


# set region to default settings 
g.region n=12:47:21.1074N s=8:18:00.2682N w=74:52:26.4E e=77:16:58.8E || error_routine "g.region"


#connection to database
db.connect driver=mysql database="project"

db.login driver=mysql database=project user=root password=1234
db.connect -p
db.tables -p

for n in {0..1}
do
#import Vector map
v.in.db driver=mysql database=project table=rain x=lon_dd y=lat_dd output=tempera --o key=st_code || error_routine "v.in.db"
d.mon start=x0 || error_routine "d.mon"
d.vect tempera || error_routine "d.vect"
sleep 5;

#import Raster map
v.to.rast input=tempera output=tempera1 --o use=attr column=rain_fall || error_routine "v.to.rast"
d.mon start=x1|| error_routine "d.mon"
d.rast tempera1 || error_routine "d.rast"
sleep 7;
#show classified interpolated map:

r.surf.idw input=tempera1 output=tempera2 --o || error_routine "r.surf.idw"
d.mon start=x2 || error_routine "d.mon"
d.rast tempera2 || error_routine "d.rast"
sleep 8;


# close PNG output
d.mon stop=x0  || error_routine "d.mon stop"
d.mon stop=x1  || error_routine "d.mon stop"
d.mon stop=x2  || error_routine "d.mon stop"
sleep 3600;
done
# remove internal tmp stuff:
$GISBASE/etc/clean_temp  || error_routine "clean_temp"
rm -rf $TMPDIR/grass6-$USER-$GIS_LOCK

# done.
echo "Generated "

rm -rf "$tmp"  # remove session files from tmpdir

echo "done"
echo
echo
echo
echo "Goodbye from GRASS GIS"
echo
if [ -x "$GRASS_BATCH_JOB" ] ; then
   echo "Batch job '$GRASS_BATCH_JOB' (defined in GRASS_BATCH_JOB variable) was executed."
   exit 0
fi


Please notify where to use cron and how to set the time intervals that will automatically execute every 1 hr.

Thank You

With Regards





      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/grass-dev/attachments/20090513/4c0d3aa9/attachment-0001.html


More information about the grass-dev mailing list