Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftp verify/retry

Status
Not open for further replies.

cleansedbb

Technical User
Feb 11, 2002
95
US
I have a cron script that ftps sitestat files from my other pc daily. I've been noticing that some files dont transfer or come in garbage. is there a way to verify a file transfer via shell script? if so can you make it retry on fail?

Thanks.


below is what I have so far:

#!/bin/sh
##########
cd /log/file/path
#
ftp -inv <<END_FTP
open site.com
user name pass
cd /path/to/stats/
bin
mget *.gif
mget *.jpg
asc
mget *.html
bye
END_FTP
################
exit 0



 
You could add logic for a summed list file. In other words do this before you ftp:


for FILES in `ls ${DIR}`
do
sum -r ${FILES} >> list.txt
done

Then make sure that you ftp over the list.txt and then reverify the sum values, try this:

#!/usr/bin/ksh -p

COUNT=1
TCOUNT=`cat list.txt|wc -l`
let TCOUNT=TCOUNT+1

while [ ${COUNT} -ne ${TCOUNT} ]
do
VAL=`head -${COUNT} list.txt|tail -1`
#!/usr/bin/ksh -p

COUNT=1
TCOUNT=`cat list.txt|wc -l`
let TCOUNT=TCOUNT+1

while [ ${COUNT} -ne ${TCOUNT} ]
do
VAL1=`head -${COUNT} list.txt|tail -1|awk '{print $1}'`
VAL2=`head -${COUNT} list.txt|tail -1|awk '{print $2}'`
FILE=`head -${COUNT} list.txt|tail -1|awk '{print $3}'`
CHK1=`sum -r ${FILE}|awk '{print $1}'`
CHK2=`sum -r ${FILE}|awk '{print $2}'`
if [ ${CHK1} -eq ${VAL1} ] && [ ${CHK2} -eq ${VAL2} ]
then
print &quot;File: ${FILE} passed.&quot;
else
print &quot;File: ${FILE} failed.&quot;
fi
let COUNT=COUNT+1
done

That should work.
 
If you're a Perl person, try the Net::FTP module. I use that all of the time and it's very easy to write and use. Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top