Avatar of SWB-Consulting
SWB-Consulting

asked on 

How to unfreeze a bash script that get frozen when opening a document with openoffice in order to export it as PDF?

I created a bash script that reads the content of a directory looking for .doc and .wpd files.
Once a file is found then will try to export the file to PDF by using this command :

/usr/bin/oowriter -display localhost:1.0 -accept="socket,host=localhost,port=2002;urp;" -headless "macro:///Standard.Module1.ConvertWordToPDF($1)";

The problem is that in case that the file is damaged or the file has the wrong extension then openoffice will throw an exception and the script will freeze and no more files in the directory will be processed.

Does anyone of you know how to prevent the script to freeze and keep processing files after an exception?


#
# conversion
#		
for i in `find $FOLDER -type f -name "*.doc" -o -name "*.wpd"`; 
do 
	
	echo ""; 
	echo "*** found $i"; 
	chmod 444 $i;
	chown apache:apache $i;	 
		case $i in 
        *.doc)
		FILE_BASENAME=`basename "$i" .doc`;;
        *.wpd)
		FILE_BASENAME=`basename "$i" .wpd`;;
	esac
		FILE_DIRNAME=`dirname "$i"`;
	PDF="$FILE_DIRNAME/$FILE_BASENAME.pdf";
	
	echo "*** checking $PDF";
	if [ -r $PDF ]
	then
		echo "*** already created $PDF";		
	else
		/usr/bin/convert2pdf "$i";
		sleep 5;				
		if [ -r $PDF ]
		then
			echo "*** pdf created $PDF";
			chmod 444 $PDF;
			chown apache:apache $PDF;
		else
			echo "*** error $PDF";
		fi
	fi			 	
done

Open in new window

Shell Scripting

Avatar of undefined
Last Comment
nognew

8/22/2022 - Mon