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?

1 Answer 1

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).

1
  • 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
    Commented Oct 17, 2018 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .