我可以 ssh 某个地方,运行一些命令,然后给自己一个提示吗? [英] Can I ssh somewhere, run some commands, and then leave myself a prompt?
问题描述
我发现自己需要登录各种服务器,设置环境变量,然后交互工作.
例如
$ ssh anviljla@anvil$ 出口 V=你好jla@anvil$ export W=worldjla@anvil$ 回声 $V $W你好世界
我怎样才能组合前几个命令,然后让自己留在提示处?
类似于:
$ ssh anvil --on-login 'export V=hello;出口W=世界;'jla@anvil$ 回声 $V $W你好世界
显然这是一个模型问题.我真正要问的是我如何通过 ssh 连接到另一台机器,运行一些命令,然后像手动运行它们一样继续?"
可能最简单的事情是:
<前>$ ssh -t 主机'cmd1;cmd2;sh -i'如果要设置变量,请执行以下操作:
<前>$ ssh -t 主机'cmd1;cmd2;FOO=你好 sh -i'请注意,这是一个可怕的黑客行为,最好将所需的初始命令放在脚本中并执行以下操作:
<前>$ scp 设置主机:~$ SSH 主机主机$.设置I find myself needing to log into various servers, set environment variables, and then work interactively.
e.g.
$ ssh anvil
jla@anvil$ export V=hello
jla@anvil$ export W=world
jla@anvil$ echo $V $W
hello world
How can I combine the first few commands, and then leave myself at a prompt?
Something like:
$ ssh anvil --on-login 'export V=hello; export W=world;'
jla@anvil$ echo $V $W
hello world
Obviously this is a model problem. What I am really asking is 'how do I ssh to a different machine, run some commands, and then continue as if I'd run them by hand?'
Probably the simplest thing is:
$ ssh -t host 'cmd1; cmd2; sh -i'
If you want to set variables, do:
$ ssh -t host 'cmd1; cmd2; FOO=hello sh -i'
Note that this is a terrible hack, and you would be much better off putting your desired initial commands in a script and doing:
$ scp setup host:~ $ ssh host host$ . setup
这篇关于我可以 ssh 某个地方,运行一些命令,然后给自己一个提示吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!