0

This sort of builds off of my previous question about GRASS but it is a different issue.

I have a Python script which should kick off a GRASS batch job in a docker container like so:

grass_batch_job = f"""
        docker run -v {GRASS_DIR}:/data mundialis/grass-gis-stable /bin/bash -c '
        rm -r /data/{uuid}_mapset;
        grass76 -c epsg:3036 -e /data/{uuid}_mapset;
        export GRASS_BATCH_JOB="/data/script/vectorize_output.sh {uuid}";
        grass76 /data/{uuid}_mapset/PERMANENT;
        unset GRASS_BATCH_JOB'
    """

You can see that I have some {uuid} references floating about, this is to keep data separated that may be due to multiple processes running in parallel. This seems to be where the problem comes in:

I need to be able to pass this uuid variable to the shell script which i have exported as GRASS_BATCH_JOB, so that it knows which image to select to operate on, as per the shell script itself:

r.external -o input=/data/$1_paths.tif output=dummy_img
g.region -ap raster=dummy_img
r.reclass input=dummy_img output=dummy_img_nulled rules=/data/script/reclass_rules.txt
r.thin input=dummy_img_nulled output=thinned
r.to.vect thinned output=vectorized type=line
v.out.ogr input=vectorized output=/data/out/out_lines2.shp format=ESRI_Shapefile --overwrite

But when I try to do this, I get an error complaining that it can't find the shell script:

ERROR: Job file </data/script/vectorize_output.sh fake_UUID> has been defined in the 'GRASS_BATCH_JOB' variable but not found. Exiting.

(fake_UUID is just a debug UUID value)

Is there a way to get GRASS to recognize that I want to pass a variable to this batch job before running it?

1

Here's a way that the seems to work. You need to export the UUID variable on the same command line as starting grass. Then within the batch job script the variable $UUID is available in the enviroment,

micha@TP480:tmp$ cat << EOF > test_args.sh
> echo "$UUID"
> g.region -p
> EOF
micha@TP480:tmp$ chmod u+x test_args.sh 
micha@TP480:tmp$ export GRASS_BATCH_JOB="./test_args.sh" 
micha@TP480:tmp$ export UUID="Hello"; grass
Cleaning up temporary files...
Starting GRASS GIS...
Executing <./test_args.sh> ...
Hello
projection: 99 (Israel 1993 / Israeli TM Grid)
zone:       0
datum:      towgs84=-48,55,52,0,0,0,0
ellipsoid:  grs80
north:      552860.19929577
south:      552241.02033451
west:       219814.56338028
east:       220395.65457746
nsres:      1.00028911
ewres:      1.00015697
rows:       619
cols:       581
cells:      359639
Execution of <./test_args.sh> finished.
Cleaning up default sqlite database ...
Cleaning up temporary files...
micha@TP480:tmp$ unset GRASS_BATCH_JOB

As you see, the variable $UUID can be referenced from within the script when it was exported before starting grass. Somewhat clunky, but it might help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.