Trigger email from script if the Special Character replacement is successfull

Hello Gurus,

I have a script developed...

#!/bin/bash
#---------------------------------------------------------------------
# This pScript will remove/replace the special characters fromfiles
#--------------------------------------------------------------------- 
trxdate="`date +%Y%m%d_%H%M%S`"
cd /mnt/G/Inbound/Pre-Prod/GEM/From_O/Scriptprocess
INBOUND=/mnt/G/Inbound/Pre-Prod/GEM/From_O/Scriptprocess
INBOUND2=/mnt/G/Inbound/Pre-Prod/GEM/From_O


CNTS=`ls $INBOUND/ECEPYO.dat | wc -l`
echo "$CNTS"
if (( CNTS == 0 ))
then
echo "file."
else
while [ ${CNTS} -ne 0 ]
do
CURRENTFILE=`ls ECEPYO.dat | head -1` 
echo "$CURRENTFILE"

#	remove/replace the special char
sed -e 's/'/ /g' -e 's/\\/ /g' -e 's/é/ /g' -e 's/�//g' -e 's/-/ /g' -e 's/-/-/g' -e 's/�//g' -e 's/`/ /g' $CURRENTFILE >> $CURRENTFILE.tmp 

#copying file to folder	
cp -p $INBOUND/$CURRENTFILE.tmp $INBOUND2/$CURRENTFILE
#removing the files	
rm $CURRENTFILE
rm $CURRENTFILE.tmp
CNTS=`ls $INBOUND/ECEPYO.dat | wc -l`
echo "$CNTS"
done
fi
exit 0	

Here my question is , I have used sed commmand to replace the special characters found in the file, so I want to trigger email (in the email I want to have which special character is replaced) if any of the listed special characters replaced to some email id like : xyz@gmail.com. Also all files will not have special characters , so some may have and some may not have.

Can anyone please help me here.

Thanks
Nandu

Nanduedi,

Are asking for an email if a "special character" was found in ECEPYO.dat ?

I would also separate the function of checking for "special characters" from the function of removing them, with

#!/bin/bash

SDIR=/mnt/G/Inbound/Pre-Prod/GEM/From_O/Scriptprocess 
FILE=ECEPYO.dat
ADDR=xyz@gmail.com

cd $SDIR || exit 1
test -f ${FILE} || exit 2
test -s ${FILE} || exit 0

TEMP=$(mktemp)
LIST=$(mktemp)
trap "rm -f ${TEMP} ${LIST}" EXIT

for special in ' \\ é � - � � \`; do
  grep -n "${special}" ${FILE} > ${LIST}
  
  if [[ -s ${LIST} ]]; then
    echo
    echo "${special}": $(cut -d: -f1 ${LIST})
  fi >> ${TEMP}
done

if [[ -s ${TEMP} ]]; then
  mailx -s "SpecialCharacters were found" ${ADDR} < ${TEMP}
fi

(! untested !)

` and \ are "special characters"?

I do have to admit to some trepidations. The directory the script changes into is a subdirectory of /mnt ? This is typically used for temporary mounts.

Why the while loop? Your script only processes a single file: ECEPYO.dat .

Simplifying your original script:

#! /bin/bash

FDIR=/mnt/G/Inbound/Pre-Prod/GEM/From_O
SDIR=$FDIR/Scriptprocess 
FILE=ECEPYO.dat

cd $SDIR || exit 1
test -f ${FILE} || exit 0

sed -e 's/'/ /g' \
    -e 's/\\/ /g' \
    -e 's/é/ /g' \
    -e 's/�//g' \
    -e 's/-/ /g' \
    -e 's/�/-/g' \
    -e 's/�//g' \
    -e 's/`/ /g' $FILE >> $FDIR/$FILE