Advertisement

07.23.2008 at 11:05PM PDT, ID: 23591123 | Points: 500
[x]
Attachment Details

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

Asked by SWB-Consulting in Bourne-Again Shell (bash)

Tags: , , ,

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?

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
#
# 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
[+][-]07.24.2008 at 01:17AM PDT, ID: 22076974

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628