1

Connected to a remote server via SSH.

On occasion, I run a specific bash script. When certain conditions are met (it's work completed successfully), I wish to be automatically logged out of the SSH tunnel. In the normal login shell, I simply type logout to logout.

I am unable to do this from a bash script. If I put logout in a bash script, the error is:
logout: not login shell: use `exit'

Query: How do you automatically log yourself out of an SSH connection from a bash script?

3

If you want to logout after the successful completion of /path/to/shell-script.sh, use:

/path/to/shell-script.sh && logout

A ruder way to do it would be to have the script kill the parent:

kill -HUP "$PPID"

(PPID is a variable that is set by the bash shell, for one).

  • Thankyou, the second option is what I was seeking in this situation, require all the "logic" in a single file, in this specific cash. Merci! – Mtl Dev Oct 17 '18 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.