如何通过SSH运行Shell脚本,以使远程计算机的环境与本地计算机的环境相似? [英] How can I run a shell script via SSH such that the environment of the remote computer is similar to that of the local computer?

查看:78
本文介绍了如何通过SSH运行Shell脚本,以使远程计算机的环境与本地计算机的环境相似?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我欢迎改写我的问题,因为我不确定问题到底是什么.

I welcome rephrasing of my question, because I'm not sure exactly what the problem is called.

我正在尝试使用以下格式的命令通过SSH运行Shell脚本:

I am trying to run a shell script via SSH using a command of the following form:

ssh -o StrictHostKeyChecking=no lxplus0035 "cd ~/test; bash script1.sh"

执行此操作时,复杂的脚本 script1.sh 会中断,出现许多语法错误,操作数错误和其他错误.一个例子如下:

When I do this, the complex script script1.sh breaks with many syntax errors, operand errors and other errors. An example is as follows:

stty: standard input: Invalid argument

在本地系统和远程系统中(通过SSH会话连接时)(而不是通过SSH)直接运行时,脚本可以正常运行.为什么通过SSH执行脚本会导致这些问题?

The script works fine when run directly, not via SSH, in the local system and in the remote system (when connected in an SSH session). Why might executing the script via SSH cause these problems?

推荐答案

stty 问题与您的环境无关,这是由于SSH命令未为您分配TTY(什么是伪TTY分配?(SSH和Github)).为 ssh 添加 -t 参数应该可以解决此问题.

The stty problem is not related to your environment, it's a result of the SSH command not allocating you a TTY (What is Pseudo TTY-Allocation? (SSH and Github)). Adding -t argument for ssh should fix it.

更多信息:

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