Trigger email from script if the Special Character replacement is successfull


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Trigger email from script if the Special Character replacement is successfull
# 1  
Old 05-07-2015
Trigger email from script if the Special Character replacement is successfull

Hello Gurus,

I have a script developed...

Code:
#!/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

Moderator's Comments:
Mod Comment Start using code tags, thanks.
# 2  
Old 05-19-2015
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
Code:
#!/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:
Code:
#! /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


Last edited by derekludwig; 05-19-2015 at 09:34 AM.. Reason: typo
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Special character replacement

Hi Guys, I have a file which needs to be replaced with tab delimited AA§Orgin Name§Mapping based on prod_usa§§§§ BB§Date§2019-08-11 23:30:01§§§§ I am trying below code sed 's// /g' test.txt Expected AA|Orgin Name|Mapping based on prod_usa||| BB|Date|2019-08-11 23:30:01|||| (6 Replies)
Discussion started by: rohit_shinez
6 Replies

2. Shell Programming and Scripting

Shell script question in special character

when I execute the unix commands its works normally in the 1st part. When I the tried the same in shell scripting the directory is not displayed in 2nd part example. please let me know what needs to be done. Unix : client=~zsvdbs echo $client /shome/zsvhome/zsvdbs Using... (3 Replies)
Discussion started by: keerthi2016
3 Replies

3. Shell Programming and Scripting

calling another script if it's contains SUCCESSFULL how?

Hi all, i'm a newbie here, I'm just wondering how can i call my second script if it's contain successfull. script1.sh how can i call my 2nd script if he contain SUCCESSFULL script2.sh SUCCESSFULL please advise, Thanks, (10 Replies)
Discussion started by: nikki1200
10 Replies

4. Shell Programming and Scripting

Use arrow touch in a script shell without special character

Hello, I have a problem when i execute the script underneath. If i tape azerty 123 and i use the arrow touch, in the file /tmp/test i have the caracter #!/usr/bin/ksh clear echo "Taper l adresse IP de la partition a creer :" tput cup 1 48 read Adress echo $Adress echo "${Adress}" >>... (0 Replies)
Discussion started by: khalidou13
0 Replies

5. UNIX for Dummies Questions & Answers

banner character replacement

Can we able to replace the character # in banner command with some other characters. Can we able to blink the character in Kornshell (1 Reply)
Discussion started by: sivakumar.rj
1 Replies

6. Shell Programming and Scripting

Perl Script Syntax to Extract Everything After Special Character

Hi, I am writing a Perl script that reads in many lines, if a line meets the criteria I want to edit, it. For example, the script will return the following example line... test=abc123 All I want to do is strip off the "test=" and just be left with the abc123. In my script I can easily... (3 Replies)
Discussion started by: edrichard
3 Replies

7. Shell Programming and Scripting

Script not successfull in cron

Hi, I have a script to FTP the files to other unit. Manually this script is running fine & files are getting transferred. But running the same script using crontab does not transfer files, although the cron log shows that the file was executed. PLz suggest (2 Replies)
Discussion started by: sandeep_kmehra
2 Replies

8. Shell Programming and Scripting

Sed-Special character replacement

Hi I want to replace ./testsed.ksh with testsed.ksh ./ is to be removed scriptnm=`sed -e 's/\.///' $0 does not work Please help (3 Replies)
Discussion started by: usshell
3 Replies

9. Shell Programming and Scripting

Character replacement

Hi, I am working on a command that replaces some occurrences of quotation marks in file. The quotation mark cannot be the first or the last character in line and cannot be preceded or followed by a comma. I am not an expert in regular expressions, but I managed to create the following... (2 Replies)
Discussion started by: piooooter
2 Replies

10. Shell Programming and Scripting

Special Character Check in Shell script

Hi, I'm currently working on a project that requires parsing xml file. One of the field in the xml is shown below (don't remember exactly): <variable="ITEM">12345678</variable> I coded my script keeping in mind that the value denoted in bold will always be a number. After getting just the... (1 Reply)
Discussion started by: mradul_kaushik
1 Replies
Login or Register to Ask a Question

Featured Tech Videos