1833187 Members
3157 Online
110051 Solutions
New Discussion

usage of cksum

 
SOLVED
Go to solution
Rushank
Super Advisor

usage of cksum

Hello,

I need your help in a script.

The existing script looks for a directory and if there are any files present then 'rcp' it over to the remote server and mv the the same file to a local 'done' directory. If by any reason rcp was not successful we have no clue if the file has transmitted fully before it move it to the done directory.
I came to know about sum /cksum command to verify the data integrity of the file.
I would like to insert this cksum within script to ensure successful rcp.

Thanks in advance.
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: usage of cksum

I used to use that all the time, just add :

in ksh:
$filesumremote=`remsh hostwherefilewent cksum filepath_of_file_onremotehost`
$filesumlocal=`cksum filepath`

Then compare the two results.


live free or die
harry
Live Free or Die
Rushank
Super Advisor

Re: usage of cksum

Thanks Harry,

What is the result I'll get for sucessful and unsucessful file transfer..?

Deshpande Prashant
Honored Contributor

Re: usage of cksum

HI
Try this.

rcp :/tmp
REMOTE=`remsh "/usr/bin/cksum /tmp/file-name" |awk '{print $1}'`

LOCAL=`/usr/bin/cksum |awk '{print $1}'`

echo $REMOTE $LOCAL

if [ $LOCAL=$REMOTE ]
then
echo "Transfer OK"
else
echo "Transfer Not OK"
fi


HTH
Prashant.
Take it as it comes.
harry d brown jr
Honored Contributor

Re: usage of cksum

When the two variables do not equal each other, and neither one is equal to 0 (zero), then you had a transmission problem. Don't worry about the return codes.

live free or die
harry
Live Free or Die
Rushank
Super Advisor

Re: usage of cksum

Thanks Prashant , That was very useful..
How do I than ask the script to retransmit the file if it's "Not OK"

I'm very new to this scripting..

harry d brown jr
Honored Contributor

Re: usage of cksum

Sorry, I messed up the syntax, hereis a more useful version:

#!/bin/ksh
file1=`cksum /tmp/hello|cut -d" " -f1,2`
file2=`remsh vpart2 cksum /tmp/hello|cut -d" " -f1,2`
echo $file1 "---" $file2
if [ "${file1}" != "${file2}" ];then
echo panic - files do not match
echo do some import stuff here
fi
Live Free or Die
Deshpande Prashant
Honored Contributor
Solution

Re: usage of cksum

HI
You can put in a loop if you like.

while true
do
rcp :/tmp
REMOTE=`remsh "/usr/bin/cksum /tmp/file-name" |awk '{print $1}'`

LOCAL=`/usr/bin/cksum |awk '{print $1}'`

echo $REMOTE $LOCAL

if [ $LOCAL=$REMOTE ]
then
echo "Transfer OK"
break
else
echo "Transfer Not OK, Trying again."
echo "Transfer of local file not OK" |sendmail SYSADMIN

fi

#--
I personally feel If transfer not ok, page to sysadmin, in stead on looping.


HTH
Prashant.
Take it as it comes.
Darrell Allen
Honored Contributor

Re: usage of cksum

I used to do the same thing with cksum.

One other thing, in case you haven't thought of it yet, is to verify the source file is not in use (busy). It would be if still being written. I used:

InUse=`fuser filename 2>/dev/null`
if [ X"$InUse" = X ]
then
echo not in use
else
echo in use
fi

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)