问题描述
我欢迎改写我的问题,因为我不确定问题到底是什么.
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.
更多信息:
- http://go2linux.garron.me/linux/2010/11/ssh-t-open-pseudo-tty-run-commands-remote-server-809/
- http://capistranorb.com/documentation/faq/why-does-something-work-in-my-ssh-session-but-not-in-capistrano/
这篇关于如何通过SSH运行Shell脚本,以使远程计算机的环境与本地计算机的环境相似?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!