简体   繁体   English

如何ssh到远程ubuntu vm并将shell从csh更改为bash

[英]How to ssh to remote ubuntu vm and change the shell from csh to bash

Linux machine A & machine B has common called ses. Linux机器A和机器B的共同名叫ses。 On machine A we have the python script to ssh to machine B & run series of shell commands like cd to a dir, source few files & run a python script called clean.py 在机器A上,我们有python脚本ssh到机器B并运行一系列shell命令(例如cd到dir),提供一些文件并运行一个名为clean.py的python脚本

clean_command = "cd /ws/vprahlad-bgl/pats;source env.sh;source /auto/pysw/ats/env.sh;uname -a;python clean.py"

The id ses has passwordless login enabled between machine A & machine B. When ssh ses@machine B %s clean_command is giving error as badly placed ()'s id ses在机器A和机器B之间启用了无密码登录。当ssh ses@machine B %s clean_command给出错误时, badly placed ()'s

By default, ses on machine B has csh & the command inside clean.py works only with bash shell 默认情况下,机器B上的ses具有csh,clean.py内部的命令仅适用于bash shell

I tried changing the shell from csh to bash in remote command but prompts for password, however other commands works fine 我尝试在远程命令中将外壳从csh更改为bash,但提示输入密码,但是其他命令也能正常工作

ses@A:~$ ssh ses@B 'uname -a;uptime;echo $SHELL; chsh -s /bin/bash'
Linux B 3.10.0-693.11.6.el7.x86_64 #1 SMP Thu Dec 28 14:23:39 EST 2017 x86_64 x86_64 x86_64 GNU/Linux
15:01:54 up 5 days, 22:44,  1 user,  load average: 0.10, 0.07, 0.05
/bin/csh
This is your AD password:

Is there way to ssh and change the shell to bash to source those files from csh 有没有办法通过ssh和将shell更改为bash来从csh中获取这些文件

chsh is meant for occasional, interactive, use. chsh用于偶尔的,交互式的使用。 It determines your login shell. 它确定您的登录外壳。 Changing it to bash is a very good idea on most systems, for many reasons -- newcomers to UNIX should only be using csh if your software environment insists on it (some SAP installations seem to standardize on it, for instance.) 出于多种原因,在大多数系统上将其更改为bash是一个好主意-UNIX的新手只能在您的软件环境坚持使用csh情况下才使用csh (例如,某些SAP安装似乎对其进行了标准化。)

So my solution is: login to B via SSH, run 'chsh', provide your password, choose /bin/bash or /usr/bin/bash as your startup shell, then quit. 所以我的解决方案是:通过SSH登录到B,运行“ chsh”,提供密码,选择/bin/bash/usr/bin/bash作为启动shell,然后退出。 From now on your scripts will run remotely using bash . 从现在开始,您的脚本将使用bash远程运行。

Your login shell is determined by the last entry in the /etc/passwd - line. 您的登录Shell由/ etc / passwd-行中的最后一个条目确定。 But you can call a bash-Script without login. 但是您无需登录即可调用bash脚本。 Just put the crucial statements of these env.sh and the "python clean.py"-statement in a script and call it with " bash script.bash " This should work. 只需将这些env.sh的关键语句和“ python clean.py”语句放入脚本中,然后使用“ bash script.bash”进行调用即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM