Comments on 2025-03-24 Speeding up operations on a remote server with reusing the ssh connection

In your particular case, except for the initial upload the rest of the job is entirely local to the server. So you could just run a single script via one ssh invocation like this:

scp project.zip some_server/~ # them's the breaks :-(
{ echo 'rm -rf ~/project-old' ;
  echo 'cp -r ~/project ~/project-old' ;
  echo 'unzip -o ~/project.zip -d ~/project' ;
} | ssh some_server

There should be a pipe symbol before my last ssh line. Sorry – it is not obvious how to show code in comments; I tried raw html and rst, neither seems to work.


Ian

aceecat 2025-03-25 17:02 UTC


You’re right – but the actual script I have is much longer and does many things. It also runs some commands on the server and uses their output to make decisions about what to do next (including locally), so your idea, while useful, will not cover all cases I need. Still, thanks, you had a good point!

– mbork 2025-03-25 20:01 UTC