Reputation: 279
i'm pretty new with python and i'm trying to make a simple ssh session and run a simple command. i know that i can use "paramiko" but i decide to use pexpect/pxssh and i installed the last version.
my code:
#!/usr/bin/env python
from pexpect import *
import pexpect
import pxssh
import getpass
import time
import os
try:
s = pexpect.pxssh()
hostname = raw_input('hostname:')
username = raw_input('usernmae:')
s.login((hostnmae,username,password)
s.sendline ('uptime')
s.prompt()
print s.before
s.sendline ('ls -l')
s.prompt()
print s.before
s.logout()
except pxssh.ExceptionPxssh, e:
print "pxssh failed"
print str(e)
but it fails with the following:
$ python pssh.py
File "pssh.py", line 15
s.sendline ('uptime')
^
SyntaxError: invalid syntax
can someone please help?
Thanks a lot!
Upvotes: 1
Views: 1112
Reputation: 3244
There are various problems in your code:
It should be
s = pexpect.pxssh.pxssh()
Check for extra "(" and variable hostname
on line.
s.login((hostnmae,username,password)
And you need password for the ssh before above line.
import getpass()
password = getpass.getpass()
Upvotes: 1