ssh with command…Plus the shell

纵饮孤独 提交于 2019-11-28 20:40:51

Variation on the other answers really, use the -t option of ssh to force pseudo-tty allocation:

ssh -t me@machine ./executeMyScript '&&' bash -i

How about

    ssh me@machine ./executeMyScript '&&' bash -i

You have to quote the && so it will be passed to the remote machine instead of swallowed by the local shell.

Quote a ';' character and you can change your start directory, too:

    ssh me@machine ./executeMyScript '&&' cd /developmentDirectory ';' bash -i

Put something like this at the end of the script you want to run:

bash -li

That starts Bash as an interactive login shell. It's not perfect, since you'll be missing out on things like TERM forwarding, but it might be adequate to your needs.

If it isn't sufficient, I'd just make two separate ssh calls, one to run the script and another to log me in.

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.

user3174711

This works for me.

/usr/bin/ssh -t yourdomain.com "cd /directory; bash -i"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!