SSH : Remotely run a script and stay there

前端 未结 1 935
醉梦人生
醉梦人生 2021-02-20 03:28

I wish to run a script on the remote system and then wish to stay there. Running following script:-

ssh user@remote logs.sh

This do run the scr

相关标签:
1条回答
  • 2021-02-20 03:52

    Try this:

    ssh -t user@remote 'logs.sh; bash -l'
    

    The quotes are needed to pass both commands to ssh. The -t option forces a pseudo-tty allocation.

    Discussion

    Consider:

    ssh user@remote logs.sh;bash -l
    

    When the shell parses this line, it splits it into two commands. The first is:

    ssh user@remote logs.sh
    

    This runs logs.sh on the remote machine. The second command is:

    bash -l
    

    This opens a login shell on the local machine.

    The quotes were added above to prevent the shell from splitting up the commands this way.

    0 讨论(0)
提交回复
热议问题