You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by Tom Plassman <tp...@worthington.k12.oh.us> on 2002/10/02 22:35:48 UTC

Running FOP from Unix script

I am running the following unic script in the background on my Sun box. 
The idea being that my application generates the needed xml and then
creates a SPECS file telling fop what xsl and xml to use and what pcl to
output.  This works fine for the first set of specs passed to the
script.

For example if the first application requests a TRANSPORT REQUEST it
prints fine and all subsequent TRANSPORT REQUESTS print fine.  But if
someone then requests a LETTER, the fop script still prints out a
TRANSPORT REQUEST and if I delete the TRANSPORT REQUEST xml, fop stops
and will not run because that xml is missing.  Despite the fact that the
specs actually requested another xml.

I don't know if this is something inherent in fop or something in the
way the unix script is written.

Script follows---------------------------------------

#!/bin/sh
#

JAVA_HOME=/usr/java
export JAVA_HOME

i=1
count=1
while [ "$i" = 1 ]
do
	isfile=`ls /data02/WSS/FAC/Data/ | grep fopspecs`
	if [ "$isfile" = fopspecs ]
	then

		for arg in `cat /data02/WSS/FAC/Data/fopspecs`
		do
		if [ "$count" = 4 ]
                        then theprinter=$arg
                             count=5
                fi
		if [ "$count" = 3 ]
                        then thepcl=$arg
                             count=4
                fi
                if [ "$count" = 2 ]
                        then thexml=$arg
                             count=3
                fi
                if [ "$count" = 1 ]
                        then thexsl=$arg
                             count=2
                fi
		done
		/apps/fop/fop.sh -xsl $thexsl -xml $thexml -pcl $thepcl
> /tmp/foptrack
		rm /data02/WSS/FAC/Data/fopspecs
		lp -d $theprinter $thepcl > /dev/null2>&1
		rm $thexml
		rm $thepcl
	fi
	sleep 10
done
�-------------------------------------------------------------------

Thanks
Tom Plassman
Worthington Schools

Re: Running FOP from Unix script

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Tom Plassman wrote:
...
> For example if the first application requests a TRANSPORT REQUEST it
> prints fine and all subsequent TRANSPORT REQUESTS print fine.  But if
> someone then requests a LETTER, the fop script still prints out a
> TRANSPORT REQUEST and if I delete the TRANSPORT REQUEST xml, fop stops
> and will not run because that xml is missing.  Despite the fact that the
> specs actually requested another xml.
> 
> I don't know if this is something inherent in fop or something in the
> way the unix script is written.
It's a problem in the script. In fact, one of the most ugly shell
scripts i've ever seen, and boy, I've seen a lot of bad stuff.

> i=1
> count=1
Problem here: the count is never reset to 1, therefore
your parameter assignments work only the first time.

Apart from this, and the comments already given by Roland:

> 	isfile=`ls /data02/WSS/FAC/Data/ | grep fopspecs`
> 	if [ "$isfile" = fopspecs ]
You seem to test whether a specific file exists. Tis is what
  if [ -f fopspecs ]
was invented for.

J.Pietschmann


RE: Running FOP from Unix script

Posted by Roland Neilands <rn...@pulsemining.com.au>.
Tom,

> The idea being that my application generates the needed xml and then
> creates a SPECS file telling fop what xsl and xml to use and
> what pcl to
> output.  This works fine for the first set of specs passed to the
> script.
>
> For example if the first application requests a TRANSPORT REQUEST it
> prints fine and all subsequent TRANSPORT REQUESTS print fine.  But if
> someone then requests a LETTER, the fop script still prints out a
> TRANSPORT REQUEST and if I delete the TRANSPORT REQUEST xml, fop stops
> and will not run because that xml is missing.  Despite the
> fact that the
> specs actually requested another xml.
>
> I don't know if this is something inherent in fop or something in the
> way the unix script is written.

Aargh, If I were you I would smack whoever wrote your script liberally about
the head! Or preferably give them some scripting lessons.

Test a few things yourself here: you will learn a bit.
1. Test each of your fop.sh command lines, you seem unsure what you actually
want.
2. Test your script output.
   eg write the command lines to be used to screen or to a file
   or  use `sh -x yourscript.sh` to debug
3. Time the FOP run. Is 10 seconds sleep enough? You might be getting
duplicates.

Some suggestions
Use `cron` to run it.
Set default umask on the directory to allow creation/deletion by appropriate
users.
Use all spaces or all tabs (if you must) to structure, don't mix them, it
can look unreadable to other people.
Use file extensions (.xml, .xsl) & identify the arguments that way.
OR better still
string ALL the fop args correctly into the file in the first place & pass it
to fop using cat or echo.
Don't use a fixed filename if you expect multiple requests either.

Cheers,
Roland