[GRASS-user] bash script

Hi

I’m trying to run GRASS and import raster map using a bash script but I’m getting an error saying r.in.gdal not found.

What have I done wrong? see the script below.

#!/bin/sh

#variable to customize:

path to GRASS software main directory

GISBASE=/usr/bin/grass64

path to GRASS database

GISDBASE=$HOME/grassdem

GISBASELIB=/usr/lib/grass64

nothing to change below

MAP=SRTMDEM.tiff
LOCATION=/home/tgumede1/
grassdem

generate temporal LOCATION:

TEMPDIR=Floods
mkdir -p $GISDBASE/$TEMPDIR/tmp

save existing $HOME/.grassrc6

if test -e $HOME/.grassrc6 ; then
mv $HOME/.grassrc6 /$GISDBASE/$TEMPDIR.grassrc6
fi

echo “LOCATION_NAME: $TEMPDIR” > $HOME/.grassrc6
echo “MAPSET:tmp” >> $HOME/.grassrc6
echo “DIGITIZER: none” >> $HOME/.grassrc6
echo “GISDBASE: $GISDBASE” >> $HOME/.grassrc6
export GISBASE=$GISBASE

first our GRASS, then the rest

export PATH=$GISBASE:$GISBASELIB/scripts:$PATH

first have our private libraries:

export LD_LIBRARY_PATH=$GISDBASE/lib:$GISBASELIB/lib:$LD_LIBRARY_PATH

import raster map into new location:

r.in.gdal -eo in=$MAP out=dem location=$LOCATION
if [$? -eq 1] ; then
echo “An error occured. Stop.”
exit 1
fi

restore saved $HOME/.grassrc6

if test -e $HOME/.grassrc6 ; then
mv $HOME/.grassrc6 /$GISDBASE/$TEMPDIR.grassrc6
fi


Kind Regards
TS Gumede
CSIR, Meraka Institute
072 258 1650

Sandile Gumede wrote:

[snip]

# first our GRASS, then the rest
export PATH=$GISBASE:$GISBASELIB/scripts:$PATH

Try
export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"

See also etc/init.sh for inspiration

Markus M

I’m using ubuntu, I installed grass from the synaptic. So the script to start grass is in /usr/bin then the file name is grass64 (/usr/bin/grass64) and the scripts are in /usr/lib/grass64 then inside grass64 folder you get other folder like scripts and so on. That is why in my script I wrote:

start GRASS

GISBASE=/usr/bin/grass64

path to the scripts

GISBASELIB=/usr/lib/grass64

But I tried to export the PATH you gave me, still giving me an error of r.in.gdal not found

On Thu, Jun 24, 2010 at 9:16 AM, Markus Metz <markus.metz.giswork@googlemail.com> wrote:

Sandile Gumede wrote:

[snip]

first our GRASS, then the rest

export PATH=$GISBASE:$GISBASELIB/scripts:$PATH

Try
export PATH=“$GISBASE/bin:$GISBASE/scripts:$PATH”

See also etc/init.sh for inspiration

Markus M


Kind Regards
TS Gumede
CSIR, Meraka Institute
072 258 1650

Sandile Gumede wrote:

I'm using ubuntu, I installed grass from the synaptic. So the script to
start grass is in /usr/bin then the file name is grass64 (/usr/bin/grass64)
and the scripts are in /usr/lib/grass64 then inside grass64 folder you get
other folder like scripts and so on. That is why in my script I wrote:

# start GRASS
GISBASE=/usr/bin/grass64

/usr/bin/grass64 is the script starting GRASS, not a directory

in your case I think
GISBASE=/usr/lib/grass64

followed by
export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"

should do it because r.in.gdal should be in $GISBASE/bin = /usr/lib/grass64/bin

now tell GRASS where its libraries are:
export LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH
also do
export GRASS_LD_LIBRARY_PATH=$LD_LIBRARY_PATH

$GISDBASE/lib is nonsense because GISDBASE is the location of a GRASS database

HTH,

Markus M

# path to the scripts
GISBASELIB=/usr/lib/grass64

But I tried to export the PATH you gave me, still giving me an error of
r.in.gdal not found

On Thu, Jun 24, 2010 at 9:16 AM, Markus Metz
<markus.metz.giswork@googlemail.com> wrote:

Sandile Gumede wrote:
>
> [snip]
>
>
> # first our GRASS, then the rest
> export PATH=$GISBASE:$GISBASELIB/scripts:$PATH

Try
export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"

See also etc/init.sh for inspiration

Markus M

--
Kind Regards
TS Gumede
CSIR, Meraka Institute
072 258 1650

On 24/06/2010 10:02, Sandile Gumede wrote:

I'm using ubuntu, I installed grass from the synaptic. So the script to
start grass is in /usr/bin then the file name is grass64
(/usr/bin/grass64) and the scripts are in /usr/lib/grass64 then inside
grass64 folder you get other folder like scripts and so on. That is why
in my script I wrote:

I assume you know http://grass.osgeo.org/wiki/GRASS_and_Shell

I do regularly run GRASS Batch jobs as described there, and this works fine.

Hermann

Sandile Gumede wrote:

I'm using ubuntu, I installed grass from the synaptic. So the script to
start grass is in /usr/bin then the file name is grass64
(/usr/bin/grass64) and the scripts are in /usr/lib/grass64 then inside
grass64 folder you get other folder like scripts and so on. That is why
in my script I wrote:

Then your GISBASE should be /usr/lib/grass64

The location of /usr/bin/grass64 is irrelevant - it is only a startup script to set appropriate environment variables, etc. You are doing all this in your script so you don't need to use the grass64 script at all (and GRASS doesn't need it for anything else).

Hopefully that makes it clearer?

Paul

Thanks, The only problem I have now when I’m running the script, it gives me an error saying LOCATION_NAME not set. See below:

#!/bin/sh

#variable to customize:

path to GRASS software main directory

export GISBASE=/usr/lib/grass64

path to GRASS database

GISDBASE=$HOME/grassdata

nothing to change below

MAP=$1
LOCATION=$2

generate temporal LOCATION:

TEMPDIR=tmp
mkdir -p $GISDBASE/$TEMPDIR/temp

save existing $HOME/.grassrc6

if test -e $HOME/.grassrc6 ; then
mv $HOME/.grassrc6 /$GISDBASE/$TEMPDIR.grassrc6
fi

echo “LOCATION_NAME: $TEMPDIR” > $HOME/.grassrc6
echo “MAPSET:tmp” >> $HOME/.grassrc6
echo “DIGITIZER: none” >> $HOME/.grassrc6
echo “GISDBASE: $GISDBASE” >> $HOME/.grassrc6

path to GRASS settings file:

export GISRC=$TEMPDIR/.grassrc6

first our GRASS, then the rest

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

first have our private libraries:

export LD_LIBRARY_PATH=$GISBASE/lib:$LD_LIBRARY_PATH
export GRASS_LD_LIBRARY_PATH=$LD_LIBRARY_PATH

settings for graphical output

PNGOUTPUTDIR=$TEMPDIR

current date

DATE=LC_ALL=C date -R | tr -s ' ' ' ' | cut -d' ' -f2,3,4 | tr -s ' ' '_'
export GRASS_PNGFILE=$PNGOUTPUTDIR/grass6_recent_floods_${DATE}.png
export GRASS_TRUECOLOR=TRUE
export GRASS_WIDTH=900
export GRASS_PNG_COMPRESSION=1

use process ID (PID) as lock file number:

export GIS_LOCK=$$

the algorithms goes here

error_routine () {
echo “ERROR: $1”
exit 1
}

import DEM data set.

cd /home/tgumede1/grassdata
r.in.gdal input=TRMMLast1day.tif output=rainfall

set region to default settings

g.region rast=rainfall

import DEM data set.

r.in.gdal input=Dem_CF.tif output=dem

set region to default settings

g.region rast=dem

On Thu, Jun 24, 2010 at 10:55 AM, Paul Kelly <paul-grass@stjohnspoint.co.uk> wrote:

Sandile Gumede wrote:

I’m using ubuntu, I installed grass from the synaptic. So the script to
start grass is in /usr/bin then the file name is grass64
(/usr/bin/grass64) and the scripts are in /usr/lib/grass64 then inside
grass64 folder you get other folder like scripts and so on. That is why
in my script I wrote:

Then your GISBASE should be /usr/lib/grass64

The location of /usr/bin/grass64 is irrelevant - it is only a startup script to set appropriate environment variables, etc. You are doing all this in your script so you don’t need to use the grass64 script at all (and GRASS doesn’t need it for anything else).

Hopefully that makes it clearer?

Paul


Kind Regards
TS Gumede
CSIR, Meraka Institute
072 258 1650