<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic RE: Python Script for remote SSH without password in ExtremeSwitching (EXOS/Switch Engine)</title>
    <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28849#M4579</link>
    <description>Hi everibody!&lt;BR /&gt;
Can I run this command in the same way?&lt;BR /&gt;
scp2 vr "VR-Default" username@172.20.1.1:config.cfg config.cfg&lt;BR /&gt;
&lt;BR /&gt;</description>
    <pubDate>Thu, 05 Feb 2015 06:33:00 GMT</pubDate>
    <dc:creator>eyeV</dc:creator>
    <dc:date>2015-02-05T06:33:00Z</dc:date>
    <item>
      <title>Python Script for remote SSH without password</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28846#M4576</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
I want to create a universal port profile which will run a python script in order connect to a remote ssh host and check some health information. &lt;BR /&gt;
&lt;BR /&gt;
I've tried the following &lt;BR /&gt;
&lt;BR /&gt;
import pexpectimport exshexpect&lt;BR /&gt;
exosPrompt = '::--:--::'&lt;BR /&gt;
p = exshexpect.exshspawn(exosPrompt, exsh.clicmd)&lt;BR /&gt;
p.sendline('ssh vr "VR-OAM" root@192.168.140.190')&lt;BR /&gt;
idx = p.expect([passPrompt, pexpect.EOF, pexpect.TIMEOUT])&lt;BR /&gt;
p.sendline('mysecretpassword')&lt;BR /&gt;
p.sendline('exit')&lt;BR /&gt;
&lt;BR /&gt;
But i always get the prompt to enter it manually ignoring the two last commands.&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Sotiris&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Wed, 04 Feb 2015 23:31:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28846#M4576</guid>
      <dc:creator>Sotiris_Salloum</dc:creator>
      <dc:date>2015-02-04T23:31:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Script for remote SSH without password</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28847#M4577</link>
      <description>Since you are actually trying to use the ssh program, the EXOS shell is getting in the way.&lt;BR /&gt;
My suggestion is to invoke ssh directly and just use pexpect.&lt;BR /&gt;
The challenge with this method is how to determine the VR number for ssh.&lt;BR /&gt;
E.g. VR-Mgmt = 0, VR-Default=2&lt;BR /&gt;
Try running the CLI command:&lt;BR /&gt;
   run script cli2json.py -d show virtual-router&lt;BR /&gt;
Then look for  "vrId": &lt;NUMBER&gt; when name2 is VR-OAM&lt;BR /&gt;
&lt;BR /&gt;
the vrId is the number for -r below&lt;BR /&gt;
&lt;BR /&gt;
import pexpect&lt;BR /&gt;
p = pexpect.spawn('/exos/bin/ssh -r 2  &lt;A href="https://mailto:root@192.168.140.190" target="_blank" rel="nofollow noreferrer noopener"&gt;root@192.168.140.190&lt;/A&gt;')&lt;BR /&gt;
idx = p.expect(['password', pexpect.EOF, pexpect.TIMEOUT])&lt;BR /&gt;
p.sendline('mysecretpassword')&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
p.sendline('exit')&lt;BR /&gt;
&lt;BR /&gt;&lt;/NUMBER&gt;</description>
      <pubDate>Thu, 05 Feb 2015 06:33:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28847#M4577</guid>
      <dc:creator>Dave_Hammers</dc:creator>
      <dc:date>2015-02-05T06:33:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Script for remote SSH without password</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28848#M4578</link>
      <description>Thanks Dave ,&lt;BR /&gt;
&lt;BR /&gt;
It worked like a charm !&lt;BR /&gt;
&lt;BR /&gt;
Regards&lt;BR /&gt;
Sotiris</description>
      <pubDate>Thu, 05 Feb 2015 06:33:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28848#M4578</guid>
      <dc:creator>Sotiris_Salloum</dc:creator>
      <dc:date>2015-02-05T06:33:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Script for remote SSH without password</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28849#M4579</link>
      <description>Hi everibody!&lt;BR /&gt;
Can I run this command in the same way?&lt;BR /&gt;
scp2 vr "VR-Default" username@172.20.1.1:config.cfg config.cfg&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Thu, 05 Feb 2015 06:33:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28849#M4579</guid>
      <dc:creator>eyeV</dc:creator>
      <dc:date>2015-02-05T06:33:00Z</dc:date>
    </item>
    <item>
      <title>RE: Python Script for remote SSH without password</title>
      <link>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28850#M4580</link>
      <description>As another thought about determining the VR number, you could includes something like this to allow VR names to be translated to numbers automaticially in your script.&lt;BR /&gt;
&lt;BR /&gt;
Example:&lt;BR /&gt;
&lt;BR /&gt;
def vrNameToNumber(vrName):&lt;BR /&gt;
    vrId = None&lt;BR /&gt;
    with open('/proc/net/vr','r') as f:&lt;BR /&gt;
        for l in f.readlines():&lt;BR /&gt;
            rslt = l.split()&lt;BR /&gt;
            if rslt[3] == vrName:&lt;BR /&gt;
                vrId = int(rslt[0])&lt;BR /&gt;
                break&lt;BR /&gt;
    return vrId&lt;BR /&gt;
&lt;BR /&gt;
print vrNameToNumber('VR-OAM')&lt;BR /&gt;
print vrNameToNumber('VR-Default')&lt;BR /&gt;
&lt;BR /&gt;</description>
      <pubDate>Sun, 08 Feb 2015 04:39:00 GMT</pubDate>
      <guid>https://community.extremenetworks.com/t5/extremeswitching-exos-switch/python-script-for-remote-ssh-without-password/m-p/28850#M4580</guid>
      <dc:creator>Dave_Hammers</dc:creator>
      <dc:date>2015-02-08T04:39:00Z</dc:date>
    </item>
  </channel>
</rss>

