remote execution of find -exec

Hi folks

 I am working on a script which lists files of a specific pattern on a remote m/c and tar&zip them to another remote m/c via a centralized server. 

M/C details:

remote1 - OSF1 vayu V5.1 2650 alpha
remote2 - cygwin based windows server
central - SunOS phys-chenab 5.8 Generic_117350-61 sun4u sparc SUNW,Sun-Fire-15000

LAYOUT
*******

remote1(vayu) -------> central (chenab) ----------> remote2 (cygwin windows)

Have a issue with the script which seriously retards me . The logic is to check if a particular file has already been transferred , and if not transfer the same . This checking happens at the remote side through remsh. This part works well when executed directly on remote1 but fails when executed from central server.

set -f;cd /usr1/smscomn/data/cards/spool/ ;find /usr1/smscomn/data/cards/spool/ -name "CS507.11.[0-9]*.47.*" -exec bash -c ' grep $0 /usr1/smscomn/data/cards/status_vayu | grep success ; if [ `echo $?` -eq 0 ] ;then printf "$0 copied \n" ; else printf " $0 transferred already \n" ; fi ' {} {} \; ;set +f

remsh vayu "set -f;cd /usr1/smscomn/data/cards/spool/ ; find /usr1/smscomn/data/cards/spool/ -name "CS507.11.[0-9]*.47.*" -exec bash -c ' grep $0 /usr1/smscomn/data/cards/status_vayu | grep success ; if [ `echo $?` -eq 0 ] ;then printf " copied"; echo $0 ; else printf $0 transferred ; fi ' {} {} \; ;set +f "

Output:

copiedbash
copiedbash
copiedbash
copiedbash

$0 parameter of bash -c should be filename output of find but why is it pointing to prog name which is bash .

Moreover when i change bash -c to sh -c , i expect output to be "copiedsh" ; but its still "copiedbash"

Can you please provide some light on whats happening? . I am open to corrections and suggestions and even harsh rebuke over insanity of the code.

The one-line-remsh approach is much too complicated. There are too many issues to deal with even though it might be possible make it work eventually.
e.g.
Which computer expands "*".
When we match double quote characters, what characters are between the pairs of double quotes? What characters are not between double quotes?
Which computer breaks the command line on seeing a semi-colon?

You will be best advised to create the script on the remote server as a properly laid out readable script, and then execute the script with:

remsh servername -l username -n "/pathtoscript/scriptname"

Note: You may not require the "-n" switch in this context.

Your suggesstion is quite acceptable and i have implemented it. Thanks for your suggestion . Still the vagueness of the code haunts me and keeps me trying to debug it repeatedly.

Figuring out what exactly is happening is more than enough for me as it shall explain me shell's construct .

Any other suggestions ????