通过paramiko load.bash的ssh

2024-05-12 18:20:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想自动化通过ssh(putty)执行的相同操作。 使用putty连接之后,我的.bashrc被加载(这样我就可以使用别名了)。如果我尝试在Python中执行此操作,则别名sanity是不可见的:

sanity: command not found

使用source .bashrc不是解决办法。在

^{pr2}$

Tags: sourcenotsshcommandbashrcfoundputtysanity
2条回答

bash手册页:

Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt

因此,如果要使用别名,必须首先设置expand_aliases选项。在

因为您是在ssh上运行命令,所以没有运行登录shell,因此.bashrc不是源代码。在

请看这里的答案:https://superuser.com/questions/306530/run-remote-ssh-command-with-full-login-shell

编辑:

调用exec_command时尝试设置get_pty=True

否则,请尝试强制登录shell

exec_command('bash -l -c "sanity;"')

相关问题 更多 >