Re: issue while doing pexpect ssh

2015-09-10 Thread harirammanohar159
Hey,

its resolved by small tweak :)
do child.sendline('logout') instead of child.logout()

Thanks...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-09 Thread harirammanohar159
On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm...@gmail.com  wrote:
> Some where i am missing simple logic :)
> 
> =
> child = pexpect.spawn('ssh hari@hostname')
> child.logfile = sys.stdout
> child.expect('hari\'s Password: ')
> =
> 
> getting error as follows:
> 
> child.expect('hari\'s Password: ')
> TypeError: must be str, not bytes
> ===
> 
> Thanks...

Hey All,

I am able to achieve this using pxssh.. thank you for help...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-09 Thread harirammanohar159
On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm...@gmail.com  wrote:
> Some where i am missing simple logic :)
> 
> =
> child = pexpect.spawn('ssh hari@hostname')
> child.logfile = sys.stdout
> child.expect('hari\'s Password: ')
> =
> 
> getting error as follows:
> 
> child.expect('hari\'s Password: ')
> TypeError: must be str, not bytes
> ===
> 
> Thanks...

Hey Laura,

spawnu worked for handling the unicode, thank you for that, yes i have already 
tried paramiko, it didnt worked for the same purpose (tried both sftp client 
and ssh client of paramiko module; finally while doing su getting the error as 
expecting tty terminal...)

fabric will work but it is up to only python 2.7

so just i am trying to work out with pexpect whether it will be of any use or 
not.

(my goal is to login to remote server then do su then execute commands...)

Thank you for spawnu, now i got stuck with freezing issue similar to it is not 
returing to the shell prompt...its on waiting...i had to press ctrl+c

===
child.sendline(password)
child.expect('-bash-4.1$')
child.sendline('ls')
print(child.before)
child.sendline('su - user1')
child.expect('-bash-4.1$')
child.sendline('pwd; hostname')
print(child.before)
child.close()
=
output:


hari's Password: 
ls

WARNING. You have accessed a private computer system.
Unauthorized access,use,connection,or entry is not permitted
and constitutes a crime punishable by law. We reserve the
right to fully pursue criminal and civil legal penalties.
All individuals using this computer system with or without proper
authority are subject to having all their activities monitored
and recorded. Anyone using this system implicitly consents to
this monitoring. Any evidence of suspected criminal activity
revealed by such monitoring may be provided to law enforcement officials.


su - user1

lsTotal users logged in under your name (via BoKS): 3 (2 on this host)
Total users logged in (via BoKS): 8324 (2 on this host)



#
#   For Authorized Use Only #
#   #
#   Activities on this system are subject to being monitored#
#   or recorded for all users, authorized or unauthorized.  #
#   Use of the system is considered consent to such monitoring. #
#   Any evidence of possible criminal activity may be provided  #
#   to law enforcement. #
#   #
#



-bash-4.1$ ls
-bash-4.1$ su - user1
-bash-4.1$


^CTraceback (most recent call last):
  File "./rmcomments.py", line 16, in 
child.expect('-bash-4.1$')
  File 
"/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py",
 line 1451, in expect
timeout, searchwindowsize)
  File 
"/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py",
 line 1466, in expect_list
timeout, searchwindowsize)
  File 
"/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py",
 line 1535, in expect_loop
c = self.read_nonblocking(self.maxread, timeout)
  File 
"/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py",
 line 958, in read_nonblocking
r, w, e = self.__select([self.child_fd], [], [], timeout)
  File 
"/ceopt/utils/python/3.4.3/custommodules/lib/python3.4/site-packages/pexpect/__init__.py",
 line 1717, in __select
return select.select(iwtd, owtd, ewtd, timeout)
KeyboardInterrupt



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-09 Thread Laura Creighton
>Hey All,
>
>I am able to achieve this using pxssh.. thank you for help...

Great to hear it.  Good luck with the crazies.
Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-09 Thread harirammanohar159
On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm...@gmail.com  wrote:
> Some where i am missing simple logic :)
> 
> =
> child = pexpect.spawn('ssh hari@hostname')
> child.logfile = sys.stdout
> child.expect('hari\'s Password: ')
> =
> 
> getting error as follows:
> 
> child.expect('hari\'s Password: ')
> TypeError: must be str, not bytes
> ===
> 
> Thanks...

Hi Laura,

Basically its the same, no difference if i keep su user1...
i am getting the desired output with a single host, but if i keep for loop for 
multiple hosts, remaining are skipped saying as below:

pexpect.TIMEOUT: Timeout exceeded.

During handling of the above exception, another exception occurred:

pexpect.TIMEOUT: Timeout exceeded.


only 1st host is getting executed. how to control child.logout() and make for 
loop continue...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-09 Thread Laura Creighton
In a message of Wed, 09 Sep 2015 01:58:30 -0700, harirammanohar...@gmail.com wr
ites:

>Thank you for spawnu, now i got stuck with freezing issue similar to it is not 
>returing to the shell prompt...its on waiting...i had to press ctrl+c
>
>===
>child.sendline(password)
>child.expect('-bash-4.1$')
>child.sendline('ls')
>print(child.before)
>child.sendline('su - user1')
>child.expect('-bash-4.1$')
>child.sendline('pwd; hostname')
>print(child.before)
>child.close()

>WARNING. You have accessed a private computer system.


Any doubts we had about whether the computer policy authorities
as this place are 'nuttier than 2 trees full of squirrels' are
now put to rest.  I just hope I am not helping you do things that
is going to end up with them trying to put you in jail.  Poor you.

>su - user1
>
>lsTotal users logged in under your name (via BoKS): 3 (2 on this host)
>Total users logged in (via BoKS): 8324 (2 on this host)
>-bash-4.1$ ls
>-bash-4.1$ su - user1
>-bash-4.1$

Okay.
Instead of waiting for that bash-4.1 prompt
after you issue your su, issue whoami
and wait to see if it returns user1.

That way we can see if the problem is with expect waiting for the prompt
which for some reason it is not seeing, or whether it is just lost, lost,
lost.

Also, for informational purposes try your su without the '-'
just "su user1", and see if it is some part of the 'provide an environment
similar to what the user would get if the user logged in directly'
ability of su that is confusing things.

Laura


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-09 Thread harirammanohar159
On Tuesday, 8 September 2015 17:07:24 UTC+5:30, hariramm...@gmail.com  wrote:
> Some where i am missing simple logic :)
> 
> =
> child = pexpect.spawn('ssh hari@hostname')
> child.logfile = sys.stdout
> child.expect('hari\'s Password: ')
> =
> 
> getting error as follows:
> 
> child.expect('hari\'s Password: ')
> TypeError: must be str, not bytes
> ===
> 
> Thanks...

Hi,

can you check it and let me know the way...

Thanks...
-- 
https://mail.python.org/mailman/listinfo/python-list


issue while doing pexpect ssh

2015-09-08 Thread harirammanohar159
Some where i am missing simple logic :)

=
child = pexpect.spawn('ssh hari@hostname')
child.logfile = sys.stdout
child.expect('hari\'s Password: ')
=

getting error as follows:

child.expect('hari\'s Password: ')
TypeError: must be str, not bytes
===

Thanks...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-08 Thread Laura Creighton
In a message of Tue, 08 Sep 2015 04:37:09 -0700, harirammanohar...@gmail.com wr
ites:
>Some where i am missing simple logic :)
>
>=
>child = pexpect.spawn('ssh hari@hostname')
>child.logfile = sys.stdout
>child.expect('hari\'s Password: ')
>=
>
>getting error as follows:
>
>child.expect('hari\'s Password: ')
>TypeError: must be str, not bytes
>===
>
>Thanks...
>-- 
>https://mail.python.org/mailman/listinfo/python-list

https://pexpect.readthedocs.org/en/latest/api/pexpect.html#run-function
you want to use spawnu because you have a unicode string.

Laura
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-08 Thread Chris Angelico
On Tue, Sep 8, 2015 at 9:37 PM,   wrote:
> Some where i am missing simple logic :)
>
> =
> child = pexpect.spawn('ssh hari@hostname')
> child.logfile = sys.stdout
> child.expect('hari\'s Password: ')
> =
>
> getting error as follows:
> 
> child.expect('hari\'s Password: ')
> TypeError: must be str, not bytes
> ===

Laura's already answered your actual question. But I would recommend
using public key login rather than keying in a password; it's a lot
more secure, as it means you don't have to embed a password in your
source code (or at very best, on your hard disk in some other readable
and decryptable way). It also simplifies the transaction
significantly.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-08 Thread Laura Creighton
In a message of Tue, 08 Sep 2015 23:57:41 +1000, Chris Angelico writes:
>On Tue, Sep 8, 2015 at 9:37 PM,   wrote:
>> Some where i am missing simple logic :)
>>
>> =
>> child = pexpect.spawn('ssh hari@hostname')
>> child.logfile = sys.stdout
>> child.expect('hari\'s Password: ')
>> =
>>
>> getting error as follows:
>> 
>> child.expect('hari\'s Password: ')
>> TypeError: must be str, not bytes
>> ===
>
>Laura's already answered your actual question. But I would recommend
>using public key login rather than keying in a password; it's a lot
>more secure, as it means you don't have to embed a password in your
>source code (or at very best, on your hard disk in some other readable
>and decryptable way). It also simplifies the transaction
>significantly.
>
>ChrisA

This poor soul cannot login at all. He needs this hack to let him
su some-other-user because of a draconian policy he cannot do
anything about.  If he could just log in, one heck of a lot of
other things would be simpler for him ...

Laura

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: issue while doing pexpect ssh

2015-09-08 Thread jmp

On 09/08/2015 03:57 PM, Chris Angelico wrote:

On Tue, Sep 8, 2015 at 9:37 PM,   wrote:

Some where i am missing simple logic :)

=
child = pexpect.spawn('ssh hari@hostname')
child.logfile = sys.stdout
child.expect('hari\'s Password: ')
=

getting error as follows:

child.expect('hari\'s Password: ')
TypeError: must be str, not bytes
===


Laura's already answered your actual question. But I would recommend
using public key login [snip]

ChrisA



My 2 cents, beside the public key, use the python module paramiko, 
unless you really want to work at the low level yourself.


http://docs.paramiko.org/en/1.15/api/client.html

JM

--
https://mail.python.org/mailman/listinfo/python-list