I have a script, script-A
, which runs script-B
. When run under the terminal, it terminates as expected from Ctrl-C, but when run via ssh
it continues to silently run after Ctrl-C even though ssh
disconnects as usual.
~/bin/script-A.sh
:
#!/usr/bin/env bash
This script will create 15 empty files in your ~/log dir.
If you run it via ssh localhost ~/bin/script-A.sh
,
it will keep doing so even after having seemingly exited!
for i in $(seq 1 15); do
touch ~/log/$(date '+%Y-%m-%d--%H-%M-%S')__still_here.log
timeout --foreground 1000 ~/bin/script-B.sh
echo 'here' # if uncommented, this kills the script!!
done
~/bin/script-B.sh
:
#!/usr/bin/env bash
This script allows script-A.sh
to keep running after Ctrl-C!
function retry {
${@}
echo "here" # this is needed to repro the behavior!!
}
retry timeout 1 sleep 1000
I can reproduce this behavior on both Linux and macOS, so it seems to be intended behavior. But what precise mechanism could be causing it?
ssh -t
for this, right? – Kamil Maciorowski May 10 '23 at 03:53ssh -t
shows that it is still running after Ctrl-C. – yong May 10 '23 at 04:06