我刚刚尝试使用 Paramiko 进行 SSH 连接我的 Python/Django 应用程序与 Vyatta 服务器。不幸的是,当我尝试跑步时show interfaces
它抛出“无效命令”。但是,如果尝试从该服务器手动进行 SSH,则效果很好。我也尝试过'/vbash -c "show interfaces"'
- 相同的结果。
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-包装器并设置任意配置节点:
<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'...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)