I frequently execute programs that take a long time on several remote servers:
for NUM in {1..100}; do ssh host-{NUM}.mydomain.com /usr/bin/takesalongtime; done
Most of the time I let this run in background (i.e. in a terminal emulator while doing something else) and wait for it to finish. However, sometimes I need to break the loop and continue or re-run it later.
Is there a way to stop such a loop running in an interactive bash after the current iteration without killing the current ssh
or takesalongtime
program in the process?
I.e. I want to do something, so that the loop behaves like I inserted a break;
between the ssh
command and done
, so that it breaks the loop after completing takesalongtime
on the current remote host.