473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

pxssh submit su commands = very very slow

This works but after the su command you have to wait like 2 minutes
before each command gets executed ?
What did i do wrong ?

import pxssh

try:
s = pxssh.pxssh()
s.login ('127.0.0.1', 'gert', '123')
s.sendline ('uptime')
s.prompt()
print s.before
s.sendline ('ls -l')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.sendline ('su')
s.expect('Password:')
s.sendline ('123')
s.prompt()
print s.before
s.sendline ('df')
s.prompt()
print s.before
s.sendline ('exit')
s.logout()

except pxssh.ExceptionPxssh, e:
print "pxssh failed on login."
print str(e)
Jun 28 '08 #1
7 7341
gert:
This works but after the su command you have to wait like 2 minutes
before each command gets executed ?
s.sendline ('su')
s.expect('Password:')
A common idiom seems to be to omit the start of the expected reply
since it may not be grabbed quickly enough. Then the prompt has to time
out. Try
s.expect('assword:')

Neil
Jun 28 '08 #2
On Jun 29, 1:19*am, Neil Hodgson <nyamatongwe+thun...@gmail.com>
wrote:
gert:
This works but after the su command you have to wait like 2 minutes
before each command gets executed ?
* * * * * * s.sendline ('su')
* * * * * * s.expect('Password:')

* * A common idiom seems to be to omit the start of the expected reply
since it may not be grabbed quickly enough. Then the prompt has to time
out. Try
* * * * * * * s.expect('assword:')
I tested, but it has the same result. Each command after the su
command needs 2 minutes before pxssh display's its output.
Could there be a expat loop in pxssh or something ?

Jun 28 '08 #3
On Jun 29, 1:44*am, gert <gert.cuyk...@gmail.comwrote:
On Jun 29, 1:19*am, Neil Hodgson <nyamatongwe+thun...@gmail.com>
wrote:
gert:
This works but after the su command you have to wait like 2 minutes
before each command gets executed ?
* * * * * * s.sendline ('su')
* * * * * * s.expect('Password:')
* * A common idiom seems to be to omit the start of the expected reply
since it may not be grabbed quickly enough. Then the prompt has to time
out. Try
* * * * * * * s.expect('assword:')

I tested, but it has the same result. Each command after the su
command needs 2 minutes before pxssh display's its output.
Could there be a expat loop in pxssh or something ?
I am pretty sure it has to do with the prompt changing from $ to #
Jun 29 '08 #4
On 2008-06-28, Neil Hodgson <ny*****************@gmail.comwrote:
gert:
>This works but after the su command you have to wait like 2 minutes
before each command gets executed ?
s.sendline ('su')
s.expect('Password:')

A common idiom seems to be to omit the start of the
expected reply since it may not be grabbed quickly enough.
Then the prompt has to time out. Try s.expect('assword:')
I don't see why the first letter of the password prompt would
be dropped. Tty drivers have buffered data for as long as I've
been using Unix (25+ years). After writing the username you
can wait for an hour before calling read(), and you'll still
see the entire password prompt. I always assumed it was done
that way so the script would work for either "password:" or
"Password:".

--
Grant Edwards grante Yow! Edwin Meese made me
at wear CORDOVANS!!
visi.com
Jun 29 '08 #5
this does the same except 100 times faster ?

I don't understand the logic about the prompt, its not the same as the
output from the bash shell ?

root@r12276:~# cat ssh2.py
import pexpect
import sys

child = pexpect.spawn("ssh ge**@127.0.0.1")
#child.logfile = sys.stdout

i = child.expect(['assword:', r'yes/no'],timeout=120)
if i==0:
child.sendline('123')
elif i==1:
child.sendline('yes')
child.expect('assword:', timeout=120)
child.sendline('123')
child.expect('g***@rxxxx.ovh.net: ~')
print child.before

child.sendline('ls -l')
child.expect('g***@rxxxx.ovh.net:')
print child.before

child.sendline('su')
child.expect('assword:')
child.sendline('123')
child.expect('g***@rxxxx.ovh.net: /srv/www/gert')
print child.before

child.sendline('ls -l')
child.expect('r***@rxxxx.ovh.net:')
print child.before

Jun 29 '08 #6
On Sat, 28 Jun 2008 19:08:59 -0700, gert wrote:
this does the same except 100 times faster ?

I don't understand the logic about the prompt, its not the same as the
output from the bash shell ?

root@r12276:~# cat ssh2.py
import pexpect
import sys

child = pexpect.spawn("ssh ge**@127.0.0.1") #child.logfile = sys.stdout

i = child.expect(['assword:', r'yes/no'],timeout=120) if i==0:
child.sendline('123')
elif i==1:
child.sendline('yes')
child.expect('assword:', timeout=120) child.sendline('123')
child.expect('g***@rxxxx.ovh.net: ~') print child.before

child.sendline('ls -l')
child.expect('g***@rxxxx.ovh.net:')
print child.before

child.sendline('su')
child.expect('assword:')
child.sendline('123')
child.expect('g***@rxxxx.ovh.net: /srv/www/gert') print child.before

child.sendline('ls -l')
child.expect('r***@rxxxx.ovh.net:')
print child.before
You could try changing the prompt (pxssh appears to have a way of doing
that), but I prefer to set up passwordless, passphraseless ssh and do
each command separately. For the rootly portions, you might look into
passwordless sudo if you go that route.

Here's something about setting up passwordless, passphraseless ssh:

http://stromberg.dnsalias.org/~strombrg/ssh-keys.html

Jun 29 '08 #7
On Jun 29, 4:45*am, Dan Stromberg <dstrombergli...@gmail.comwrote:
On Sat, 28 Jun 2008 19:08:59 -0700, gert wrote:
this does the same except 100 times faster ?
I don't understand the logic about the prompt, its not the same as the
output from the bash shell ?
root@r12276:~# cat ssh2.py
import pexpect
import sys
child = pexpect.spawn("ssh g...@127.0.0.1") #child.logfile = sys.stdout
i = child.expect(['assword:', r'yes/no'],timeout=120) if i==0:
* * child.sendline('123')
elif i==1:
* * child.sendline('yes')
* * child.expect('assword:', timeout=120) child.sendline('123')
child.expect('g...@rxxxx.ovh.net: ~') print child.before
child.sendline('ls -l')
child.expect('g...@rxxxx.ovh.net:')
print child.before
child.sendline('su')
child.expect('assword:')
child.sendline('123')
child.expect('g...@rxxxx.ovh.net: /srv/www/gert') print child.before
child.sendline('ls -l')
child.expect('r...@rxxxx.ovh.net:')
print child.before

You could try changing the prompt (pxssh appears to have a way of doing
that), but I prefer to set up passwordless, passphraseless ssh and do
each command separately. *For the rootly portions, you might look into
passwordless sudo if you go that route.

Here's something about setting up passwordless, passphraseless ssh:

http://stromberg.dnsalias.org/~strombrg/ssh-keys.html
My boss does not allow me to cp a key on the phone server. I only have
a email with some commands and passwords.
Jun 29 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Noel Wood | last post by:
Hello, I have a problem that I'm sure is simple but I have searched the newsgroup and have not found it posted before so I apologize if it has been asked heaps of times before. I have a page that...
3
by: google | last post by:
Hi All, Is there way that commands executed in the query analyzer get logged automatically? TIA Joriz
2
by: Margaret Werdermann | last post by:
Hi all: I'm having a nasty time with a particularly difficult piece of code and was hoping someone might be able to help me. I have a FormMail form that originally worked perfectly. Then, I...
3
by: KJ | last post by:
Would anyone have a list of printer commands to use within printf for a deskjet printer in C. I have worked out that bold is \x1B\x28\x73\x33\x42 but i would like to have a list to perform other...
50
by: diffuser78 | last post by:
I have just started to learn python. Some said that its slow. Can somebody pin point the issue. Thans
23
by: mosesdinakaran | last post by:
Hi All, I need a small clarification in submitting the forms, Ur suggestions please. In a page I have two form and also two submit butons. (ie)
1
by: tereglow | last post by:
Hello, I am trying to convert some Expect/Tcl code into Python by using the Pexpect module. The environment is such that authenticated keys are disabled although SSH is available. I do not...
2
by: jrpfinch | last post by:
I'm attempting to use the pxssh to execute commands on a remote machine and do stuff with the output. Both machines are running SSH Version Sun_SSH_1.0, protocol versions 1.5/2.0 and Intel Solaris...
11
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.