Executing vty commands in Juniper routers using PyEZ
<p>I have a requirement where, a <code>python</code> script running in a Juniper router shell needs to execute some commands in <code>vty</code> console of the FPC. I cannot use <code>vty Â­c</code> because it may not work properly in all platforms. However, I can use <code>vty fpc0</code> and then execute the command and exit from there.</p>

<p>Is there a way to execute <code>vty</code> command using <code>PyEZ</code>? If yes, please provide the syntax. </p>

<p>Using PyEZ StartShell utility we can do something like</p>

<pre><code>from jnpr.junos.utils.start_shell import StartShell
from jnpr.junos import Device

dev = Device(host='xxxx', user='xxxx', password='xxxx')
dev.open()

with StartShell(dev) as ss:
    op = ss.run('vty fpc0', 'vty\)#')
    print op[1]
    op = ss.run('show version', 'vty\)#')
    print op[1]

dev.close()
</code></pre>

<p>or even</p>

<pre><code>dev = Device(host='xxxx', user='xxxx', password='xxxx')
dev.open()

with StartShell(dev) as ss:
    op = sh.run('cprod -A fpc0 -c "show version"')
    print op[1]

dev.close()
</code></pre>

python junos-automation pyez