Solved

Need a quick shell script to run tiff2pdf

Posted on 2007-04-03
3
755 Views
Last Modified: 2010-05-18
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
Comment
Question by:bennybutler
  • 2
3 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 18847763
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
 
LVL 58

Accepted Solution

by:
amit_g earned 125 total points
ID: 18847819
#!/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
 
LVL 48

Expert Comment

by:Tintin
ID: 18847910
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now