All,
I am using a for loop to SCP a bunch of files in a directory. I am having it then drop a .ready file name. Is there a way to check for the success of all iterations and then email upon fail or success?
Example of part of my script:
for file in $ORIGLOC/*
do
[[ -d $file ]] && continue # skip subdirectories
myfile=`basename ${file%\.*}` #remove .txt and base path
monthbefore=`date -d 'month ago' "+%Y%m"` #previous month date
mv $file $ARCHLOC/${myfile}_$monthbefore.txt >> $LOGFILE
touch $ARCHLOC/${myfile}_$monthbefore.ready
scp $ARCHLOC/${myfile}_$monthbefore DESTUSER@$DESTSERV:$DESTLOC >> $LOGFILE
if [ $? -eq "0" ]; then
echo $file Transferred Successfully at `date` >> $LOGFILE
scp $ARCHLOC/${myfile}_$monthbefore.ready $DESTUSER@$DESTSERV:$DESTLOC >> $LOGFILE
else
echo $file Transfer failed at `date` >> $LOGFILE
fi