How to automatically run a command after exiting ssh

B Faley

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?

heemayl

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

With ssh, how can you run a command on the remote machine without exiting?

From Dev

How to automatically run a command after saving a file

From Dev

How to run a command automatically after each reboot

From Dev

How to run command after ssh connection?

From Dev

How automatically ssh to cluster servers and run command there to get some information?

From Dev

How automatically ssh to cluster servers and run command there to get some information?

From Dev

Run command on remote server over SSH - without exiting

From Dev

Run command on remote server over SSH - without exiting

From Dev

Exiting if a command returns an empty string when run in a heredoc (ssh ... <<EOF)

From Dev

run command in script after an ssh

From Dev

'Exiting' to shell after a .command

From Dev

Run scripts automatically in server after ssh connection

From Dev

Run scripts automatically in server after ssh connection

From Dev

How does ssh run a command?

From Dev

How to run a command automatically everytime I log into a remote server via ssh without disconnecting the session

From Dev

Run a local command after closing an SSH connection?

From Dev

How to remain in session after exiting tailf command from remote script

From Dev

Run process after exiting putty

From Dev

Fedora how to automatically run the ssh daemon

From Dev

How to automatically run commands on SSH login?

From Dev

Automatically run script when exiting vim?

From Dev

How to run a command automatically when network disconnects

From Dev

Automatically run script/commands after connecting to OpenShift SSH

From Dev

Automatically run commands after SSH login to Windows server

From Dev

How to ssh into a remote box, run a command and keep it running after I disconnect

From Dev

I run zsh from bash after connecting SSH – how can I exit both with only one command?

From Dev

How to automatically reboot after running a command

From Dev

Run multiple commands automatically after opening command prompt

From Dev

Can I automatically run a command in webstorm after pushing to GitHub?

Related Related

  1. 1

    With ssh, how can you run a command on the remote machine without exiting?

  2. 2

    How to automatically run a command after saving a file

  3. 3

    How to run a command automatically after each reboot

  4. 4

    How to run command after ssh connection?

  5. 5

    How automatically ssh to cluster servers and run command there to get some information?

  6. 6

    How automatically ssh to cluster servers and run command there to get some information?

  7. 7

    Run command on remote server over SSH - without exiting

  8. 8

    Run command on remote server over SSH - without exiting

  9. 9

    Exiting if a command returns an empty string when run in a heredoc (ssh ... <<EOF)

  10. 10

    run command in script after an ssh

  11. 11

    'Exiting' to shell after a .command

  12. 12

    Run scripts automatically in server after ssh connection

  13. 13

    Run scripts automatically in server after ssh connection

  14. 14

    How does ssh run a command?

  15. 15

    How to run a command automatically everytime I log into a remote server via ssh without disconnecting the session

  16. 16

    Run a local command after closing an SSH connection?

  17. 17

    How to remain in session after exiting tailf command from remote script

  18. 18

    Run process after exiting putty

  19. 19

    Fedora how to automatically run the ssh daemon

  20. 20

    How to automatically run commands on SSH login?

  21. 21

    Automatically run script when exiting vim?

  22. 22

    How to run a command automatically when network disconnects

  23. 23

    Automatically run script/commands after connecting to OpenShift SSH

  24. 24

    Automatically run commands after SSH login to Windows server

  25. 25

    How to ssh into a remote box, run a command and keep it running after I disconnect

  26. 26

    I run zsh from bash after connecting SSH – how can I exit both with only one command?

  27. 27

    How to automatically reboot after running a command

  28. 28

    Run multiple commands automatically after opening command prompt

  29. 29

    Can I automatically run a command in webstorm after pushing to GitHub?

HotTag

Archive