ksh and while..do loop problem
I have a while..do loop I'm trying to get working using ksh. I have a similar script contruct for bash that goes something like this:
while line=$(line)
do
...
done < my.input.file
And this works flawlessly. I have the same setup for a script using ksh:
find /dir/structure -name "*.pgp" > /tmp/tmp.file
while processfile=$(processfile)
do
...
done < /tmp/tmp.file
Only when I run the latter loop, I get the following error:
/usr/local/bin/sdsimage.ksh: processfile: command not found
I tried enclosing the while statement in [] but that didn't help. Is there something I'm missing here? Here's the whole script if it helps:
#! /bin/ksh
#
# First, we need to find all the .ctl.pgp files that are currently out there under
# the /incoming/sdsvendor directory.
find /dir/structure/ -name "*.ctl.pgp" > /tmp/sdsfiles
cat /tmp/sdsfiles # Troubleshooting; verify the file isn't empty because we know it shouldn't be.
# Now that we have a list to work from, start processing the files by directory.
while processfile=$(processfile)
do
tempdir=`cut -c1-20 $processfile` # This gets the directory
tempseq=`cut -c51-54 $processfile` # This gets the sequence number
tempfileven=`cut -c30-37 $processfile` # Get the vendor ID from the file
tempdirven=`cut -21-28 $processfile` # Gets the vendor login ID
tempdate=`cut -c39-45 $processfile` # Gets the ccyyddd date from filename
temptype=`cut -c47 $processfile` # Gets the type of transmission
tempworkfile=`cut -c30-54 $processfile` # If everthing checks, we'll need this to work the load
tempreccode=`cut -c48-50 $processfile` # Gets the record code in case they need it for something
cd $tempdir
echo $date >> $tempdir/dailylog.$date # Adding to or creating an audit log
countfiles=`find . -name *.????$tempseq.* | wc -l` # This makes sure all the files are there
if [[ $countfiles -ne 3 ]]
then
echo "There are only $countfiles files for sequence $tempseq." >> $tempdir/errorlog.$date
echo `find . -name *.????$tempseq.*` >> $tempdir/errorlog.$date
echo "Please resend the files." >> $tempdir/errorlog.$date
echo >> $tempdir/errorlog.$date
continue # Kick out and go to the next fileset
fi
if [[ $tempdirven != $tempfildir ]] # Checks the vendor ID against the vendor name on the file
then
echo "$tempdirven ID does not match the vendor ID $tempfileven on the file." >> $tempdir/errorlog.$date
echo >> $tempdir/errorlog.$date
continue # Kick out and go to the next fileset
fi
# Now that we've checked the file against the basic constraints, we can start
# processing the files.
echo "$tempdate" >> $tempdir/dailylog.$date
echo "Sequence: $tempseq" >> $tempdir/dailylog.$date
echo "File Type: $temptype" >> $tempdir/dailylog.$date
echo "ID Code: $tempreccode" >> $tempdir/dailylog.$date
echo >> $tempdir/dailylog.$date
pgp $tempworkfile.zip.pgp > /dev/null # Decrypts .zip file
if [[ $? -ne 0 ]]
then
echo "Problem decrypting $tempworkfile.zip.pgp!" >> $tempdir/dailylog.$date
echo "Problem decrypting $tempworkfile.zip.pgp!" >> $tempdir/errorlog.$date
echo "Please resend the file using the correct Public Key." >> $tempdir/errorlog.$date
echo >> $tempdir/dailylog.$date
echo >> $tempdir/errorlog.$date
continue # If the file won't decrypt, move on to the next one
else
echo "$tempworkfile.zip.pgp decrypted successfully." >> $tempdir/dailylog.$date
fi
pgp $tempworkfile.bil.pgp > /dev/null # Decrypts .bil file
if [[ $? -ne 0 ]]
then
echo "Problem decrypting $tempworkfile.bil.pgp!" >> $tempdir/dailylog.$date
echo "Problem decrypting $tempworkfile.bil.pgp!" >> $tempdir/errorlog.$date
echo "Please resend the file using the correct Public Key." >> $tempdir/errorlog.$date
echo >> $tempdir/dailylog.$date
echo >> $tempdir/errorlog.$date
continue # If the file won't decrypt, move on to the next fileset
else
echo "$tempworkfile.bil.pgp decrypted successfully." >> $tempdir/dailylog.$date
fi
pgp $tempworkfile.ctl.pgp > /dev/null # Decrypts .ctl file
if [[ $? -ne 0 ]]
then
echo "Problem decrypting $tempworkfile.ctl.pgp!" >> $tempdir/dailylog.$date
echo "Problem decrypting $tempworkfile.ctl.pgp!" >> $tempdir/errorlog.$date
echo "Please resend the file using the correct Public Key." >> $tempdir/errorlog.$date
echo >> $tempdir/dailylog.$date
echo >> $tempdir/errorlog.$date
continue # If the file won't decrypt, move on to the next fileset
else
echo "$tempworkfile.ctl.pgp decrypted successfully." >> $tempdir/dailylog.$date
fi
num_of_images_received=`/usr/bin/pkunzip -v $tempworkfile.zip | grep tif | wc -l`
num_of_images_expected=`head -1 $tempworkfile.ctl`
if [[ $num_of_images_received -ne $num_of_images_expected ]] # Compares number of files against expected
then
echo "Incorrect image count; Process halted." >> $tempdir/dailylog.$date
echo >> $tempdir/dailylog.$date
echo "Images received: $num_of_images_received" >> $tempdir/errorlog.$date
echo "Images expected: $num_of_images_expected" >> $tempdir/errorlog.$date
echo "Process halted." >> $tempdir/errorlog.$date
echo >> $tempdir/errorlog.$date
continue # Kick out and go to the next fileset
else
echo "The number of images in the control file matches the images sent." >> $tempdir/dailylog.$date
fi
done < /tmp/sdsfiles # This loop reads the /tmp/sdsfiles file for input; should catch multiple entries in a directory.
# File cleanup
# rm /tmp/sdsfiles
exit 0 # Job completed successfully
|