Solved

Need a quick shell script to run tiff2pdf

Posted on 2007-04-03
3
751 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

759 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