How to check the file status in a remote server?

Hi All,
Thanks in Advance.

My requirement is there are some data files to be updated(some times new files get created) regularly in server A, these files are to be updated to the server B(backup server) by using SCP, I have to write a script for this purpose, before copying the files to server B, the current files in server B to be taken backup in backup floder of server B.

The problem is if the data file is new in server A it will just be copied to server B, if the data file is existing one and has updated in server A the script has to take the backup of existing file in server B & then copy the updated file from server A to server B.

After connecting to the server B using SCP how can I check whether the file is there or not (any conditional checks), then only it will be decided whether to only copy the file or taking the backup and then copy.

Your help will be greatly appreciated.

Thanks,
Raju

any help pls...

Thanks in Advance
Raju

Hi Raj,
One approach i can think of is to execuute the ls -l command on remote machine and get the list of files to Machine A.

STEP1: MachineA$ rsh MachineB ls /home/a2i8808 > /tmp/FromMachB.txt

Now check if the file you are ftping is in the list if so then again

You execute the remot command to keep the back

STEP2: MachineA$ rsh MachineB cp file1 file.backup

The STEP2 above should be in a loop for total number of files existing in MACHINEB which are same as Machine A.

STEP3: Now SCP all files.

Hope this helps.

Hi Reddy,

Thanks for your help...

I will check it & let you know the status.

Regards,
Raju