1833760 Members
2190 Online
110063 Solutions
New Discussion

shell script

 
SOLVED
Go to solution
Sanjiv Sharma_1
Honored Contributor

shell script

Hi All,

I am modifying a working script.In this script there is an rcp command to copy some files from one system to another system.

A part of the script:
*************************
if [ $age_in -gt 120 ]
then
ll $procfile >> $log_dir/instore$mt.log
cat $procfile >> $log_dir/instore$mt.log
rcp $raw_dir/instore/$procfile abcd@efgh:/user_ef/efgh/rawdat
a/instore
$par_dir/instore/rawconv.pl $raw_dir/instore/$procfile
$par_dir/instore/instoreup $raw_dir/instore/rawdata.out
cat $procfile >> $bak_dir/instore/$mth/$today.ins
$proc_dir/instore/$time.ins
rm -f $procfile
rm -f $raw_dir/instore/rawdata.out
fi
****************************

Here my requirement is to put a check on the rcp.

If the rcp is successful then proceed with the next command or else copy the content to another local folder in the same system. How do I do it?

Thanks for your help.
Everything is possible
3 REPLIES 3
Ian Dennison_1
Honored Contributor

Re: shell script

Perform an 'remsh abc@defg 'll [directory]/[filename]' |grep [filename] |wc -l

The grep and wc -l are outside the remsh, any value of 0 indicates error, any value of 1 indicates failure.

Share and Enjoy! Ian
Building a dumber user
Steven E. Protter
Exalted Contributor
Solution

Re: shell script

rcp $raw_dir/instore/$procfile abcd@efgh:/user_ef/efgh/rawdat
a/instore
rc=$?

if [ $rc ne 0 ]
echo "The rcp failed"
mailx -s "rcp failed" yourmail@yourdomain.net
fi

You could obviously remesh to the other system and run a check script but I doubt that would work if the rcp command failed.

Anyway there are dozens of possible solutions here.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Chris Vail
Honored Contributor

Re: shell script

Run a checksum on both sides of the rcp command--good for files up to 2GB.
SOURCESUM=`sum -r $SOURCFILE|awk '{ print $1 }'
DESTSUM=`rsh $DESTHOST sum -r $DESTFILE|awk '{ print $1 }'`
if test "$SOURCESUM" -eq "$DESTSUM"
then
echo "copy was successful"
else
echo "copy was unsuccessful"
fi

This guarantees a byte-for-byte copy.


Chris