Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:28:15+00:00 2026-06-03T23:28:15+00:00

I am trying to manage several cisco switches in a network I control. I

  • 0

I am trying to manage several cisco switches in a network I control. I simply want to use pexpect to log-into each one to check uptime, just to keep an eye each morning that the devices have not rebooted.

I have the pexpect portion working, but I want to list all the IP’s of the devices in a text file, and then using the python script, have it ingest these ip’s, and one by one, log into the device and do a show version command. Perhaps, if I define the pexpect commands as a module this would work, but not sure how to do that. I am new to python and tried to find the answer, but after many google searches, came up empty so wanted to try here.

Below is my attempt in automating this, but it does not work.

Here is what I have thus far.

import pexexpect
list=raw_input('Type in name of text file:' )
fo=file(list, 'r')
tt=fo.readlines()
fo.close()

for ip in tt:
    load(ip) 

child=pexpect.spawn("telnet ip") 
child.expect("password:*")
child.sendline("mypassword")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:28:16+00:00Added an answer on June 3, 2026 at 11:28 pm
    for ip in tt:
        child = pexpect.spawn("telnet %s" % ip)
        ...
    

    Apart from that, use open not file, and you don’t need to read the lines, you can simply iterate the file object. Nice would be to extract the pexpect stuff into a function:

    def inspect_ip(ip):
        ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use couchapp to manage my CouchDB application, but it's missing a
I'm trying to use Apache XMLRPC to manage posts at a small weblog service.
I am having a problem when trying to use each() twice. I have a
The Background I'm trying to use Composer to manage dependencies for WordPress plugins. I've
I am trying to manage session of users after authentication with ldap. The authentication
I'm trying to realize the same as in Spring error when trying to manage
I'm trying to manually manage some geometry (spatial) columns in a rails model. When
I am trying to work out how to manage the following relationships A Store
I'm trying to figure out how to manage my event ids. Up to this
I'm trying to get Django's manage.py to run with modified settings files. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.