By Salil Gupta
I have a script ABC which calls another script XYZ. Function of XYZ is to ftp a file from one server to another.
code for ABC:
#!/bin/ksh
PATH=/usr/bin
home/user/xyz "$@"
exit $?
~
code for xyz:
#!/bin/ksh
HOSTNAME=$1
SRCNAME=$2
DSTNAME=$3
### This file holds the outget of the FTP commands for success checking
FTPCHK=/tmp/ftpchk.$$
#touch $FTPCHK
echo "" > $FTPCHK
SRCFILE=$SRCNAME
DSTFILE=$DSTNAME
echo Source Host: $HOSTNAME
echo Source File Name: $SRCFILE
echo Destination File: $DSTFILE
echo `date` Beginning FTP download...
ftp -v ${HOSTNAME} <>$FTPCHK 2>&1
ascii
nlist ${SRCFILE}
get ${SRCFILE} ${DSTFILE}
quit
EOF
### Check for FTP errors
CHK1=`grep -c "226 Transfer complete." $FTPCHK`
CHK2=`grep -c "226 ASCII Transfer complete." $FTPCHK`
CHK3=`grep -ic "226 transfer complete" $FTPCHK`
CHK4=`grep -ic "226 File send OK." $FTPCHK`
### In NT, There should transmissions complete:
### One for the data transfer,
### One for the nlist
if [ $CHK1 -eq 2 ] || [ $CHK2 -eq 2 ] || [ $CHK1 -eq 1 -a $CHK2 -eq 1 ] || [ $CHK3 -eq 2 ] || [ $CHK4 -eq 1 ]; then
RC=0
echo "OK: FTP Transmission Worked"
echo '--------------------------------------------------------------'
cat $FTPCHK
echo '--------------------------------------------------------------'
else
RC=1
echo "ERROR: FTP Transmission Failed"
banner "ERROR"
echo '--------------------------------------------------------------'
cat $FTPCHK
echo '--------------------------------------------------------------'
fi
date
ls -al ${DSTFILE}
rm $FTPCHK
echo '---------------------------------------------------------------------'
exit $RC
In script XYZ, I am trying to ftp a file. So during ftp , whenever it shows that space is less than size of file, it should ftp the partial according to the available space and prompt a message about it and also prompt a message to outer script that inner script could not complete successfully. Hence resulting in the failure of outer script, due to partial ftp of file.
Also please post the comments about the each step of script to explain what is happening in that step. Thanks a lot in advance.