Is it possible to bind some actions which will be executed before logout from ssh session?

I mean some config like .bashrc, etc.

  • What do you want executed? A script or are you running commands that run for awhile so you want to exit and keep them running?
    – user532963
    Dec 12, 2015 at 19:13
  • 1
    I want execute just a single command. But answer not a best place for comments.
    – xiº
    Dec 12, 2015 at 19:19

1 Answer 1


If you enter the following into .bashrc (or /etc/profile, or .profile, or any other start-up script) on the remote machine:

function onexit { xmessage "Exiting..."; }; trap onexit EXIT

You can replace the xmessage command with anything you want: if you use /etc/profile you will need to make checks that bash is in a remote session, so as not to affect local sessions.

The answers here deal with exiting scripts, but are equally valid for the shell itself.

  • Works like a charm!
    – xiº
    Dec 12, 2015 at 19:59

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.