Need a quick shell script to run tiff2pdf

I need a quick shell script, bash probably, but whatever that will endlessly loop through watching a directory, and convert any files that come into it to a pdf.  Don't worry about any error checking.  I command line flags so I can set the loop time in seconds, the directory to watch and the directory to put the files into...  I'll be running many copies of it at once if it matters.

I should be able to call it like this:
tiffwatch -t 10 -s ./sourcedir -d ./destinationdir

It should call tiff2pdf $1 -o $2 which will do the conversion, I already have that working.

I just need help with the loop I guess... I dont' have time to look it all up.

Thanks




http://www.die.net/doc/linux/man/man1/tiff2pdf.1.html
LVL 1
bennybutlerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
You'd be better off changing the call to just

tiffwatch 10 srcdir dstdir

In which, case, you'd do

#!/bin/sh
if [ $# -ne 3 ]
then
    echo "Usage: $0 [sleep time] [source dir] [dest dir]" >&2
    exit 1
fi

sleep=$1
srcdir=$2
dstdir=$3

# Add various error checking for valid dirs here

cd $srcdir

while true
do
  for file in *.tiff
  do
     tiff2pdf $file -o $dstdir/$file
  done

  sleep $sleep
done


0
amit_gCommented:
#!/bin/bash

PROG_NAME=$(basename $0)

T_FLAG=1
S_FLAG=1
D_FLAG=1
TIME=""
SOURCE=""
DESTINATION=""

Usage="Usage: ${PROG_NAME} -t time -s source_dir -d destination_dir"

while getopts t:s:d: OPTION
do
        echo ${OPTION} ${OPTARG}
    case ${OPTION} in
        t) T_FLAG=0;TIME=${OPTARG};;
        s) S_FLAG=0;SOURCE=${OPTARG};;
        d) D_FLAG=0;DESTINATION=${OPTARG};;
      [?]) echo "$Usage"
           exit 1;;
    esac
done

echo ${T_FLAG}
echo ${S_FLAG}
echo ${D_FLAG}
echo ${TIME}
echo ${SOURCE}
echo ${DESTINATION}

if [ ! T_FLAG -o ! S_FLAG -o ! D_FLAG ]
then
        echo $Usage
        exit 1
fi

if [ -z "${TIME}" -o -z "${SOURCE}" -o -z "${DESTINATION}" ]
then
        echo $Usage
        exit 1
fi

cd $SOURCE

while true
do
        for i in *.tiff
        do
                    tiff2pdf $i -o ${DESTINATION}/`basename $i .tiff`.pdf
        done
       
        echo "Sleeping for $TIME"
        sleep $TIME
done
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TintinCommented:
You'll notice that amit_g has used getopts to process the command options.

There's another reason not to use flags, and that's because all of your arguments are mandatory and not optional.

Generally, you use flags as optional switches to change the behaviour of a command.

For example, the gzip command has a whole bunch of optional flags and one mandatory argument - the filename.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.