473,408 Members | 2,734 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,408 software developers and data experts.

SSH using PEXPECT

Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the
username is 'admin' and password is 'abc123' so far i have the
following code
import pexpect
import sys
import time
import os
foo = pexpect.spawn('ssh ad***@10.8.42.38')
ssh_newKey = 'Are you sure you want to continue connecting'

foo.expect = ssh_newKey
foo.send = 'yes'
foo.expect = 'password:'
foo.send = 'abc123'

-------------------------------------------------------------------------------------------------

does this look right?

if not , could someone suggest a way to do this ..
your help is much appreciated

Sep 11 '08 #1
2 5340
On Sep 10, 6:04*pm, yellowblueyel...@gmail.com wrote:
Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the
username is 'admin' and password is 'abc123' so far i have the
following code

import pexpect
import sys
import time
import os

foo = pexpect.spawn('ssh ad...@10.8.42.38')
ssh_newKey = 'Are you sure you want to continue connecting'

foo.expect = ssh_newKey
foo.send = 'yes'
foo.expect = 'password:'
foo.send = 'abc123'

--------------------------------------------------------------------------- ----------------------

does this look right?

if not , could someone suggest a way to do this ..
your help is much appreciated
https://svn.lal.in2p3.fr/projects/CM...ssh_session.py

I use a modified version of this. Simple and effective.

import ssh_session
ssh = ssh_session.ssh_session(user, host, password)
print ssh.ssh("ls -l /tmp")

Thanks Eric and Nigel!

~Sean
Sep 11 '08 #2
On Sep 10, 7:01*pm, Sean DiZazzo <half.ital...@gmail.comwrote:
On Sep 10, 6:04*pm, yellowblueyel...@gmail.com wrote:
Hey , I need toSSHinto a server .. (10.8.42.38) usingpexpectthe
username is 'admin' and password is 'abc123' so far i have the
following code
importpexpect
import sys
import time
import os
foo =pexpect.spawn('sshad...@10.8.42.38')
ssh_newKey = 'Are you sure you want to continue connecting'
foo.expect = ssh_newKey
foo.send = 'yes'
foo.expect = 'password:'
foo.send = 'abc123'
--------------------------------------------------------------------------- ----------------------
does this look right?
I am using windows and for reason it wont let me use pexpect even tho
I have CYGWIN installed
I get the following error

Traceback (most recent call last):
File "new.py", line 1, in <module>
import ssh_session
File "C:\Python25\lib\ssh_session.py", line 7, in <module>
from pexpect import *
File "C:\Python25\lib\site-packages\pexpect.py", line 85, in
<module>
support it. Pexpect is intended for UNIX-like operating
systems.""")
ImportError: No module named resource
any ideas?

Thanks
A critical module was not found. Probably this operating system does
not
support it. Pexpect is intended for UNIX-like operating systems.

>
if not , could someone suggest a way to do this ..
your help is much appreciated

https://svn.lal.in2p3.fr/projects/CM...ssh_session.py

I use a modified version of this. *Simple and effective.

import ssh_sessionssh= ssh_session.ssh_session(user, host, password)
printssh.ssh("ls -l /tmp")

Thanks Eric and Nigel!

~Sean
Sep 11 '08 #3

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

Similar topics

0
by: Steve Horsley | last post by:
I am trying to automate changing of a password for a particular user account (for use by scripts, not people). I am trying to use the command "passwd testuser" as root. Of course I can do this by...
0
by: Krutibas Biswal | last post by:
Hi, I am using a script 'unbuffer' for unbuffering my outputs when using pipes. This script is based on expect and looks like this : ----------------------------------------------...
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
20
by: valpa | last post by:
I'm a net admin for about 20 unix servers, and I need to frequently telnet on to them and configure them. It is a tiring job to open a xterm and telnet, username, password to each server. Can I...
0
by: dwelch91 | last post by:
I'm having a problem using pexpect with 'sudo' on Ubuntu 6.06 (Dapper). Here's the program: #!/usr/bin/env python import pexpect import sys child = pexpect.spawn("sudo apt-get update")...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
0
vinoj
by: vinoj | last post by:
Hi All, These are the following things which i want to do:- 1. I will be taking the ipaddress, username and password from the user using cgi ffrom the browser. 2. Now i want...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.