SSH并在连接时运行命令 [英] Ssh and run command upon connection

查看:54
本文介绍了SSH并在连接时运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过SSH连接并在连接时运行命令.我运行以下命令:

I would like to connect through SSH and run a command upon connecting. I run the following command:

ssh主机-t命令"

ssh host -t "command"

但是我需要更改一些环境变量才能运行命令,并且 eval 似乎无法正常工作.

but i need to change some environmental variables in order to run the command and it seems like eval is not working.

ssh host -t "eval `somescript.sh tcsh`; env | grep variables_that_should be_changed"

它只是不评估脚本,并说该命令不存在"somescript.sh".

It simply doesn't eval the script and says that the command does not exist "somescript.sh".

somescript.sh存在于远程计算机上,而不是从该服务器上弹出.

The somescript.sh exists on the remote machine, not the one im sshing from.

有没有办法解决这个问题?

Is there a way to solve this?

推荐答案

在同一脚本中设置环境变量并执行命令,然后在ssh上运行该脚本.在脚本存在之前,环境变量将一直有效.

Put setting the environment variables and executing the command in the same script and run that script over ssh. The environment variables will be valid until your script exists.

这篇关于SSH并在连接时运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆