Need shell script to compare directories and delete files on target server

Hello,

I need help in writing the shell script for below mentioned case.

There are 2 servers(server A, server B).
A cronjob syncs files between these 2 servers.

Existing script is copying files from A to B.
This is done using the command rsync.

However, the files are not deleted from B if they don't exist in A.

Now, I want to write a shell script for comparing the files under directories and subdirectories between A and B and delete files if they don't exist in A.

Could you please suggest this without using the rsync command.

Thanks,
Srav

what have you tried

Are you using the "--delete" option?

--delete 
This tells rsync to delete extraneous files from the receiving 
side (ones that aren't on the sending side), but only for the  
directories that are being synchronized. You must have asked 
rsync to send the whole directory  (e.g. lqdirrq or lqdir/rq) 
without using a wildcard for the directory's  contents (e.g. 
lqdir/*rq) since the wildcard is expanded by the shell and 
rsync thus  gets a request to transfer individual files, not the 
files' parent  directory. Files that are excluded from the 
transfer are also excluded from being deleted  unless you 
use the --delete-excluded option or mark the rules as only 
matching on the sending side (see the include/exclude 
modifiers in the FILTER RULES section).