We help IT Professionals succeed at work.

Script to check remote server for file

pride-it
pride-it asked
on
I am using rsync to transfer files and sync with remote server, but need to expand on script to check and see if the file exists in another directory on the same remote server, and if it does , do not run rsync command.  Would like to program in bash or ksh shell.

If the specific file in the source directory on the target server in
the  /n01/uat2/prod11iappl/ilink/11.5.0/processed directory, then I don't need to copy that file - it has already been processed.

If it doesn't exist in that directory, then I need to check if the file exists on the target server in the  /n01/uat2/prod11iappl/ilink/11.5.0/incoming directory.

If it doesn't exist  in /n01/uat2/prod11iappl/ilink/11.5.0/incoming , then you need to copy that file to that directory.

Here is the rsync command I am using:
rsync -avvvvz -e "ssh -i /home/rsync/.ssh/mesa-rsync-key" /n01/applprod/PROD11i/appl/ilink/11.5.0/processed/TO*.AXML rsync@extapuata: /agile:oaan01/uat2/prod11iappl/ilink/11.5.0/incoming/
Comment
Watch Question

CERTIFIED EXPERT

Commented:
rsync does incremental backups.  It would only transfer diffs and would not duplicate your efforts.  It is a built in functionality of rsync.  All you need to do is to use the command properly
CERTIFIED EXPERT

Commented:
From rsync man page
"It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination."
Commented:
something like this:

#/bin/bash
file=$1
if [ ! -a /n01/uat2/prod11iappl/ilink/11.5.0/processed/$file ] and [ ! -a /n01/uat2/prod11iappl/ilink/11.5.0/incoming/$file ]
then
rsync -avvvvz -e "ssh -i /home/rsync/.ssh/mesa-rsync-key" /n01/applprod/PROD11i/appl/ilink/11.5.0/processed/TO*.AXML rsync@extapuata: /agile:oaan01/uat2/prod11iappl/ilink/11.5.0/incoming/
fi

run the script and pass the filename to it, for the script above you'd run in on the target server and rsync the file from the source - or you could run the tests above over ssh, if you want to run it on the source host

Does that make sense?

Author

Commented:
Thanks, this is what I was looking for, so basically using a if then type statement and only running the command when needed.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.