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?

早过忘川 提交于 2021-02-11 15:27:22

问题


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

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"

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

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?


回答1:


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.

Further information:

  • 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/


来源:https://stackoverflow.com/questions/33926319/how-can-i-run-a-shell-script-via-ssh-such-that-the-environment-of-the-remote-com

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!