Lyle Chapman wrote:

Can anyone help?

I have a print script in bash that monitors a certain folder, when that folder is populated with a postscript file it is converted to a pdf and then printed to a selected printer.

The problem is that evertime the scripts detects a file it tries to open itimmediately even though it is still being created and this brings down our file server. Is there a way of placing a "wait until the file has been closed by the creator then start processing" the script resides below if it is any help.


For a start, 2 programs trying to simultaneously access a file should not bring down the file server.
it's possible that the file server is unstable, or a program accessing the file goes crazy when another program
opens it and brings the machine to a crawl.


I agree with Peter's reply - you should pass the postscript straight to the lp program if you can. Postscript is generally the
best format to use for printing stuff.


I suggest that you get the pdf/ps generating process to generate the file elsewhere on the file server and then move it to the location where this program checks once the file is complete. On most file systems a file move is atomic, so your script will never read an incomplete file. (just make sure you're moving the file between locations on the same file server)

Also, the pdf file won't be needed after the lp command is run - the file is spooled elsewhere on the print server before printing. But still, consider moving the file to yet another location rather than removing it, just in case something goes awry with the printer or print server.

#!/bin/sh

running=1;
while [ $running -eq 1 ]; do


This can be shortened to "while true; do" or "while :; do"

ls/home/user/workflow/Proofers/A4/*.pdf 2>/dev/null


^^^^ should be a space here ;)

if [ $? -eq 0 ] ; then
echo "A4 Files Found!!"
lp -d brothers /home/user/workflow/Proofers/A4/*.pdf 2>/dev/null
if [ $? -eq 0 ] ; then
# Possibly put in a sleep(60) or whatever here so
# files are not deleted b4 printing
echo "A4 Files Printed!!"
rm /home/user/workflow/Proofers/A4/*.pdf 2>/dev/null
fi
fi
ls/home/user/workflow/Proofers/A3/*.pdf 2>/dev/null
if [ $? -eq 0 ] ; then
echo "A3 Files Found!!"
lp -d brothers /home/user/workflow/Proofers/A3/*.pdf 2>/dev/null
if [ $? -eq 0 ] ; then
# Possibly put in a sleep(60) or whatever here so
# files are not deleted b4 printing
echo "A3 Files Printed!!"
rm /home/user/workflow/Proofers/A3/*.pdf 2>/dev/null
fi
fi


Put here "sleep 1", at least. This will make your script much less resource-heavy.

done


Mick.


-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to