1820645 Members
2009 Online
109626 Solutions
New Discussion юеВ

Script question

 
Hunki
Super Advisor

Script question

I am using rcp to copy files from one server to another , I want to add a confirmation in it that the file copied successfully. How do I do that.

thanks,
hunki
8 REPLIES 8
Piergiacomo Perini
Trusted Contributor

Re: Script question

Hi hunki,

after statement with "rcp" test the comand with
lines like this :

if [[ ${?} -eq 0 ]]
then
echo "remote copy OK"
else
echo "remote copy KO"
fi

hth
regards
pg
Sundar_7
Honored Contributor

Re: Script question

I dont beleive rcp itself offers any kind of verification mechanism.

When the copy is complete, you can run "cksum" command against the source and target files and compare the output.
Learn What to do ,How to do and more importantly When to do ?
Oviwan
Honored Contributor

Re: Script question

Hey

Check this thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1096387

my post with the checksum part.

Regards
Court Campbell
Honored Contributor

Re: Script question

As noted the $? variable will hold the return value of the rcp command. Though this may return 0, that doesn't necessarily mean the copy process was 100%. You would need to do a file comparison in order to know that the files are truly successfully copied.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
OldSchool
Honored Contributor

Re: Script question

you also need to be aware that if the destination is a different platform, checksum may not give you the answer you're looking for.

For example, an ascii file copied to windows is going to result in a different size and different chksum simply because of CR -vs CR/LF issues.
Hunki
Super Advisor

Re: Script question

Still I would require more of a one line command.

Exmaple :

rcp host:/tmp/abc .
#Need to verify here with an output message.
# and then continue with next rcp.
rcp host:/tmp/xyz .

Please suggest.
OldSchool
Honored Contributor

Re: Script question

rcp *doesn't* provide any messaging when thing work. return codes may / may no be a valid indication, i haven't tested this
Peter Nikitka
Honored Contributor

Re: Script question

Hi,

a kind of 'brute solution' is to transfer the file back again and do a local check:

flist='f1 f2 ...'
rm -f tmpfile$$
for fil in $flist
do
if rcp $fil remhost:/path/name
then
if rcp remhost:/path/name/${fil##*/} tmpfile$$
then
if cmp -s $fil tmpfile$$
then :
else print -u2 file $fil with verify error; break
fi
else print -u2 file $fil with get error; break
else print -u2 file $fil with put error; break
fi
done
rm -f tmpfile$$


mfG Peter

The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"