LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2006, 02:38 PM   #1
Harry Seldon
Member
 
Registered: Feb 2004
Distribution: SLES 9
Posts: 112

Rep: Reputation: 15
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
 
Old 04-17-2006, 04:18 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I would use a for loop:
Code:
for FILE in `find /dir/structure -name "*.pgp"`; do

// work here

done
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with do while loop. RHLinuxGUY Programming 12 02-06-2006 03:44 PM
Problem with Alias in Ksh tomcharnock Linux - Newbie 1 05-18-2005 11:59 PM
ksh check if file exists (using wildcard) problem r18044 Linux - Newbie 5 02-22-2005 07:52 AM
ksh script problem pldobs Programming 2 12-24-2003 11:38 PM
loop problem andym Linux - Newbie 0 06-05-2003 05:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration