How can I automatically run a command on the local terminal after exiting a ssh
connection? Is there any hook or event that could be handled for this?
Leverage an alias
or better a function.
For example:
ssh () { command ssh "$@"; echo foobar; }
Now, you can run:
ssh mysite
after you exit from the ssh
session, echo foobar
will be run.
Change echo foobar
with the actual command you need to run, and of course you can tack multiple commands if you want.
To make the function definition permanent, put it in your ~/.bashrc
.
Also note that, it might not always be desired to have the function named as ssh
when you want to explicitly use the external ssh
. In that case, you can use any one of the following to skip the ssh
function to get external ssh
binary:
command ssh mysite
or rename the function to something else e.g. sshfunc
:
sshfunc () { ssh "$@"; echo foobar; }
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments