I need a script to automatically scp the latest files on DIR1,DIR2 and DIR3 from Source to destination server at same place(DIR1,DIR2 and DIR3) . Further details are:
Source Server (192.168.1.5)
DIR1
DIR2
DIR3
Destination Server (192.168.1.10)
DIR1
DIR2
DIR3
do you have SSH-keys already exchanged between the servers so that the transfer can be passwordless?
We need to know that before we can provide you an answer. If you call the doctor and tell him "it hurts" he would ask "where" and "how long" too before starting to suggest a cure, no?
The output of uname -a and ps would be a good place to start on both the client (where you want to drive this from) and the server (where you are connecting too.
Can you log on from the client to the server without putting in the password? This would show that the SSH keys are in place and correct.
Thank you for that information. So, is the question "How do you know which is the latest file?" ?
Can you do something like this?:-
#Turn on shell tracing so we can see what's being called
set -x
#Work out the file I need to get
source_file=$(ssh $server "ls -1rt DIR1 | tail -1" 2>/dev/null)
echo "The source file is \"$source_file\""
# Collect the file, writing it to the directory I need
scp $server:$source_file $target_directory
It's not tested, but have a go and let's see if it gets us further. Obviously, set the server and target_directory to something useful first.
It is likely not to work first time, so paste the output in CODE tags into the thread so we can see where I have gone wrong.