Hello all; hope someone can help me cause I am going crazy trying to find a solution for (what I think is simple) issue...looked hard up and down this forum and tried several "solutions" with no avail...so here's my issue:
I have this (parent) script: copylsofdcmcadefttosftpwithmove.sh
Inside this script I have this piece of code:
if [ "$flag" = "yes" ]
then
/usr/local/bin/ssh $sftpserver mv $sftppath/$filenameshort $finaldirname >> ${_ftpdebug} 2>&1
ssh faunus:/home/dslmain/scripts/senddcmcadefttest.sh
if [ $? -ne 0 ]
then
echo "EXIT: " $?
exit
fi
echo "DONE"
else
echo "FAILED"
fi
I call another script via ssh (red text).
This is the contents of the script: senddcmcadefttest.sh
#!/bin/sh -x
node=fid
NODE=FAUNUS
_Ymd=`date +%Y%m%d`
indir=/home/dslmain/export/${node}/eft/in
sentdir=/home/dslmain/export/${node}/eft/sent
LOG="/home/dslmain/export/$node/eft/logs/eft.log.`date +%m%d`"
_temp=/utemp/tmp_logs/eftexists
if [ -s $_temp ]
then
rm $_temp
fi
_ym=`date +%m%d`
ls ${indir}/*${_ym}* > $_temp
if [ ! -s $_temp ]
then
echo "No EFT files detected" >> ${LOG}
exit 1
fi
cd ${indir}
for FILE in `cat $_temp|awk -F'/' '{print $NF}'`
do
if [ -s ${FILE} ]
then
echo "Here _UPLOAD function would have run"
echo "Snapshot of files of the day found on RBC FTP" >> ${LOG}
A=1
B=1
echo $A >> ${LOG}
echo $B >> ${LOG}
if [ ${A} -eq ${B} ]
then
echo "${FILE} was successfully uploaded to RBC" >> ${LOG}
echo "" >> ${LOG}
mv ${indir}/${FILE} ${sentdir}/${FILE}
exit 0
else
echo "${indir}/${FILE} failed to be loaded to RBC" >> ${LOG}
echo " " >> ${LOG}
exit 2
fi
else
echo "Sorry file dose not exist, or file is empty" >> ${LOG}
exit 3
fi
done
So in the child script I have 3 different scenarios (in red) where the exit code will be either 0, 2 or 3...I want to pass the correct exit code back to the parent script copylsofdcmcadefttosftpwithmove.sh so that it can be evaluated in the "if" statement...however $? is always coming back as "0"...
Thanks for reading and any assistance.
Regards
Giuliano