Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need a quick shell script to run tiff2pdf

Posted on 2007-04-03
3
Medium Priority
?
784 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

721 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