0

I'm using a shell script below for doing some rsync on a remote host. By ssh to jumphost and from there ssh again and initiating the rsync as below.

Here I need to capture the log start and end date. But somehow when i executed below script, as it prints both log at the same time.

To be more precise, here the script spawns on ServerA , then jumping to ServerB, again it jumps to ServerC and then it hit the rsync command. Here I need to capture the start time and end time of rsync command on ServerA. But this end time which is not working as expected, once the script starts it keeps record the start and end time on logs.txt, but i can see the rsync process is still progressing.

date="`date +%T-%D`"
i=folder
echo "Log started at $date for $i" >> logs.txt
ssh -T -i key user1@HOST1  "ssh -T  user2@HOST2    << EOF
rsync -av --progress source dest
EOF"
###Here the logging not excecuting after the rsync command.
if [ $? -eq 0 ]; then
echo "Log ended at $date for $i" >> logs.txt
fi

Here i would need this script to be active once the rsync process to finish on the remote host and then it proceed to the log ended part.

I already tried the wait command, but this also not helped

Any ideas appreciated

6
  • I don't think you can just pass a heredoc to ssh? You'll at least need some thing like ssh ... sh - <<EOF (newline) ... (newline) EOF? (And in your case I don't even see the point to use heredoc.)
    – Tom Yan
    Jun 20 at 9:53
  • Does the rsync command actually work? You have set your script up to only report if it is successful, which seems a bit odd, you usually need to see the log when it fails more than when it is successful.
    – terdon
    Jun 20 at 10:07
  • yes rsync command progressing in the backgroud. But without completing second echo printing
    – user183980
    Jun 20 at 10:15
  • Hang on, in the background? Why is it in the background? How different is your actual script to what you've shown us here?
    – terdon
    Jun 20 at 17:36
  • @terdon here the scenerio I'm invoking a rsync command to machine C, which jumps from A and then B ( jump host ) . I need to log the rsync start time and end time on Server A, where my script orginiates. Hope this clarifies.
    – user183980
    Jun 21 at 12:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.