For our tests we need to trigger kernel panic on a remote server (VM), via SSH:
ssh server "echo c > /proc/sysrq-trigger"
The problem is that in most cases the SSH session gets stuck, since the kernel panic happens before the connection is disconnected. There is a generic connection timeout, but this is not good enough.
Is there a way to delay the panic?
We tried to put the following in a file on the server:
# - panic.sh -
#/bin/bash
sleep 5
echo c > /proc/sysrq-trigger
And then to execute it:
ssh server "nohup panic.sh &"
But this didn't help. The SSH session waits till the sleep ends.
This happens because your script keeps all pipes open, so ssh
has to wait to see if you'll write more.
If you close them all, ssh
knows it won't receive any more output and will exit:
$ time ssh localhost 'sleep 5 < /dev/null > log 2>&1 &'
real 0m0.171s
user 0m0.013s
sys 0m0.003s
You can also do this from within the script using the exec
command before the sleep:
exec < /dev/null > log 2>&1