Is there a command in Linux which waits till it will be terminated?
I don't get why all the other replies want to use a loop here, sleep is able to wait long enough for any practical purpose and will use no clock cycles doing it.
For example it will try here to sleep for a dubious one hundred years and will likely do it enough to comply with the request anyway:
echo "Something"; sleep 36500d
Alternatively, this should block too until you type the Enter key:
echo "Something"; read foo
Try the -N
option instead. From the plink
documentation:
-N don't start a shell/command (SSH-2 only)
This is the same behavior as the ssh
option -N
, as described in the man page:
-N Do not execute a remote command. This is useful for just for-
warding ports (protocol version 2 only).
This should sleep forever without consuming any (noticeable) amount of CPU power.
echo "Something" && while true; do sleep 9999; done
I'm also not sure whether you can give a command like in the ForceCommand
clause. You may need to put the command in a shell script.
#!/usr/bin/env bash
echo "Success! Close this window to log out." && while true; do sleep 9999; done
This script should of course be in a place and have permissions such that no ordinary user on the server can write to it.
Match User sampleUser
ForceCommand /usr/bin/waitforever
Edit
I've found a command which seems more elegant:
echo "Something" && tail -f /dev/null
tail -f
waits for a file or stream to return bytes. (Otherwise useful for watching logs in realtime.) /dev/null
will never return bytes. And so the command will sleep forever.