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.