Here's a sample of my script below. Lines 1 to 11 are the information about the script. Lines 12 to 16 are the setup for some of the instructions on my script. Lines 17 to 23 are kind of like a check point to determine if the script should continue executing or if it should end right there. My issue is that the steps following the check point are being executed and are producing a false email at the end of the script. I would like to stop the email from going out if the script didn't find any files in the source directory, See my script below.
#! /bin/ksh
#Script for Great America InfoPrint Transform
Process
#Last Updated 02/29/2024
#By Harry Marion
#Terminate GVA_trans720.ksh if GVA_input folder is
empty
#Beging PDF2AFP Overlay Cover Transform
#Beging PDF2AFP PSEG Funds Transform
#Send Email with Attachment of Transformed PSEGS
SOURCE=/var/ibis/Andover_Intelligent_Print/GVA_input
DEST=/var/pd/ps600/andover720
CMD=/usr/lpp/psf/bin/pdf2afp
OPTION="FS45.pseg -r720"
#Terminate GVA_trans720.ksh if GVA_input folder is empty
destfile=`ls -l |wc -l`
sourcefile=`ls -l /var/pd/ps600/andover720 |wc -l`
if [ $sourcefile -gt 0]
then
#Beging PDF2AFP Overlay Cover Transform
$CMD -a FS45.ovly -r 720 -p1 $SOURCE/GXCP1.pdf > $DEST/GXCP1001
rm -f $SOURCE/GXCP1.pdf
#Beging PDF2AFP PSEG Funds Transform
for srcfile in `ls $SOURCE`
do
pg=0
finished=0
while [[ $finished -eq 0]]
do
pg=`echo "$pg + 1" | bc`
tmptag=`echo $srcfile | cut -f 1 -d.`
if [ $pg -lt 10]
then
destfile=$DEST/$tmptag"00"$pg
elif [ $pg -lt 100]
then
destfile=$DEST/$tmptag"0"$pg
else [ $pg -ge 100]
destfile=$DEST/$tmptag$pg
fi
echo "$CMD $srcfile -a $OPTION -p $pg > $destfile"
$CMD $SOURCE/$srcfile -a $OPTION -p $pg > $destfile
echo "file $destfile | awk '{print $2}'`"
file_stat=`file $destfile | awk '{print $2}'`
if [ $file_stat = "empty"]
then
rm $destfile
finished=1
pg=0
rm -f $SOURCE/$srcfile
fi
done
done
#Send Email with Attachment of Transformed PSEGS
GA='/var/ibis/Andover_Intelligent_Print/Attached_Files'
ls -alrt /var/pd/ps600/andover720 | grep "GA" > $GA/GA_files.txt
uuencode $GA/GA_files.txt $GA/GA_files.txt | mail -v -s "GVA_Transform_Completed" [email protected]
else
echo "$SOURCE is empty. Now exiting"
exit 1
fi