• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 791
  • Last Modified:

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
0
bennybutler
Asked:
bennybutler
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now