Adding a Fileinput loop to exsiting script.

:confused: I'm very confused on what I need to do. I've looked at if, while, but I can't seem to visualize where in my current script to put the commands.
I'm looking to read a directory /ERD/iface/data/ocom/citi/idd because there will be multible files, but I need to process them one at a time. The Process is copy the file, encrypt the file, send the file, delete the file. How do I loop this? Thank you VERY much.

# Set local variables.
SN=pgp_cfs_idd_encrypt
ENCRYPT=enc_sig_CFS_IDD
SEND=eapsend_cfs_idd_prod
MSGDIR=/home/pgp/messages/CFS
SAPDIRIN=/ERD/iface/data/ocom/citi/idd
DIRDOUT=/home/pgp/CFSUSA/outgoing_files/decrypted
DIREOUT=/home/pgp/CFSUSA/outgoing_files/encrypted
FILEIN=decrypt*  (all files are named decrypt_test_move_YYYYMMDD_HHMMSS)
FILEOUT=test_cfs_citiidd
FAILSCRIPT=Nothing
 
# ONLY send mail and first cp lines need to change below this line. #
# Error_Successmsg routine function.
Operator_Error_Msg()
{
mail -s " $SN failed in $FAILSCRIPT " mdurette@*****.com </home/pgp/CFSUSA/notes/failcfs
}
Operator_Success_Msg()
{
echo " $SUCCESSMSG was successful "
}
START=0
# Change to the $SAPDIRIN directory and copy the file from SAP to PGP
if [ $START = 0 ]; then
cd $SAPDIRIN
cp $FILEIN /home/pgp/CFSUSA/outgoing_files/decrypted/$FILEOUT > $MSGDIR/$SN 2>&1
COPY=$?
echo "The copy from SAP to PGP RC= $COPY" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=start
Operator_Success_Msg
else
FAILSCRIPT=start
exit $START
fi
# If the copy was successful, encrypt the file.
if [ $COPY = 0 ]; then
/home/pgp/scripts/$ENCRYPT \
$FILEIN \
$FILEOUT > $MSGDIR/$SN 2>&1
PGP=$?
echo "The encrypting of the decrypt file RC= $PGP" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step1_copy
Operator_Success_Msg
else
FAILSCRIPT=step1_copy
Operator_Error_Msg
exit $COPY
fi
# If encryption was successful, test if EDI server is up.
if [ $PGP = 0 ]; then
/etc/ping -c 1 ecprod >> $MSGDIR/$SN 2>&1
PING=$?
echo "The pinging of ECPROD server RC= $PING" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step2_encrypt
Operator_Success_Msg
else
FAILSCRIPT=step2_encrypt
Operator_Error_Msg
exit $PGP
fi
# If encryption and ping was successful, send the file out.
if [ $PING = 0 ]; then
/usr/local/bin/$SEND >> $MSGDIR/$SN 2>&1
SEND=$?
echo "The encrypted file has been sent RC= $SEND" >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step3_ping
Operator_Success_Msg
mail -s "Script Citibank IDD File System" -c "mdurette@*****.com" \
ops@*****.com</home/pgp/CFSUSA/notes/CFSIDDgood
else
FAILSCRIPT=step3_ping
Operator_Error_Msg
exit $PING
fi
# If the send was successful, delete the SAP file, decrypted file encrypted file.
if [ $SEND = 0 ]; then
cd $DIRDOUT
rm -f $FILEIN >> $MSGDIR/$SN 2>&1
REMV2=$?
cd $DIREOUT
rm -f $FILEOUT.pgp >> $MSGDIR/$SN 2>&1
REMV3=$?
echo "The Decrypted RC= $REMV2 file and the Encrypted RC= $REMV3 file have been deleted. " >> $MSGDIR/$SN 2>&1
SUCCESSMSG=step4_send
Operator_Success_Msg
else
FAILSCRIPT=step4_send
Operator_Error_Msg
exit $SEND
fi
# End of script.

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

Example for loop that print all the files insede directory /ERD/iface/data/ocom/citi/idd

for name_file in `ls /ERD/iface/data/ocom/citi/idd`
do
   echo $name_file
done