Paramiko“无效命令"尝试 Vyatta 的非标准命令时 [英] Paramiko "Invalid command" when trying non-standard command for Vyatta

查看:67
本文介绍了Paramiko“无效命令"尝试 Vyatta 的非标准命令时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚尝试使用 Paramiko 进行 SSH 连接,将我的 Python/Django 应用程序与 Vyatta 服务器连接起来.不幸的是,当我尝试运行 show interfaces 时,它会抛出无效命令".但是,如果尝试从该服务器手动 SSH,它工作正常.我也试过 '/vbash -c "show interfaces"' - 结果相同.

I've just tried to connect my Python/Django app with Vyatta server using Paramiko for SSHing. Unfortunately, when I try to run show interfaces it throws "Invalid command". However, if try to SSH manually from that server, it works fine. I tried also '/vbash -c "show interfaces"' - the same result.

ssh = paramiko.SSHClient()
ssh.connect('10.0.0.1','vyatta','vyatta')
stdin, stdout, stderr = ssh.exec_command('show interfaces')
# or stdin, stdout, stderr = ssh.exec_command('vbash -c "show interfaces"')
print '-'.join(stdout)
print '-'.join(stderr)

推荐答案

如前所述,您可以使用 vyatta-cfg-cmd-wrapper 并设置任何配置节点:

As mentioned earlier you can use vyatta-cfg-cmd-wrapper and set any configuration node:

<import stuff>

command = """
    /opt/vyatta/sbin/vyatta-cfg-cmd-wrapper begin
    /opt/vyatta/sbin/vyatta-cfg-cmd-wrapper set system host-name newhostname
    /opt/vyatta/sbin/vyatta-cfg-cmd-wrapper commit
    /opt/vyatta/sbin/vyatta-cfg-cmd-wrapper save
    """

sshobj = paramiko.SSHClient()
sshobj.set_missing_host_key_policy(paramiko.AutoAddPolicy())
sshobj.connect(IP,username=login,password=sshpass)
stdin,stdout,stderr=sshobj.exec_command(command)
print ''.join(stdout)
sshobj.close()

结果如下:

user@hostname$ python vyatta.py

Saving configuration to '/config/config.boot'...

这篇关于Paramiko“无效命令"尝试 Vyatta 的非标准命令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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