ssh with command…Plus the shell

前端 未结 5 2219
别跟我提以往
别跟我提以往 2020-12-14 10:08

I\'d like a command that ssh\'es into a machine, runs a command (cd or execute a script or su), and then gives me the shell. Passing a command to ssh seems to always exit.

5条回答
  •  情书的邮戳
    2020-12-14 10:53

    How about using the SendEnv option in ssh_config to send a specific environment option from your local machine to your remote machine followed up by checking for that environment variable in the remote host's configuration?

    In your .ssh/special-config-file:

    remotehost:
        SendEnv *
    

    Your local script:

    RUN_THIS_FIRST_COMMAND=blah
    ssh -F special-config-file
    

    Your remote .bash_profile:

    if [ "$RUN_THIS_FIRST_COMMAND" != "" ] ; then
        $RUN_THIS_FIRST_COMMAND
    fi
    

    You might need to check some of these lines, I just threw this together from the man pages and haven't tried any of this before. Personally I don't like having to modify both my local and remote environment for this solution.

提交回复
热议问题