Actions before logout from ssh session

6

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

I mean some config like .bashrc, etc.

xiº

Posted 2015-12-12T19:01:11.280

Reputation: 163

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? – None – 2015-12-12T19:13:31.473

1I want execute just a single command. But answer not a best place for comments. – xiº – 2015-12-12T19:19:36.797

Answers

6

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.

AFH

Posted 2015-12-12T19:01:11.280

Reputation: 15 470

Works like a charm! – xiº – 2015-12-12T19:59:01.317