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 7919801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:59:02+00:00 2026-06-03T15:59:02+00:00

I am new to expect and i was using a logic to automate diconnecting

  • 0

I am new to expect and i was using a logic to automate diconnecting telnet session where user is logged in and leave other lines as it is:

for {set i 0} {$i ==4} {incr i} {  
send "clear line vty $i\r"  
"confirm]" {send "\r"}  
"% Not allowed" {send "quit\r"; exit}  
}

it disconnects all the lines

now i use “show user” command but it’s hard for me to write a script around it, the output is not friendly enough for me.so i wrote IF statements in this for loop but it was not good and not even deserving to include here. please can somebody guide me in order to how to match strings in a output result and on the basis of the strings decide to clear line or not

  • 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-03T15:59:04+00:00Added an answer on June 3, 2026 at 3:59 pm

    That is an interesting spin on the algorithm… the problem you currently have with iterating through all the lines is that your script as-written will exit if it merely sees itself on one of the lines…

    for {set i 0} {$i == 4} {incr i} {
    send "clear line vty $i\r"
    "confirm]" {send "\r"}
    "% Not allowed" {send "quit\r"; exit}
    }
    

    If you see % Not allowed, simply bypass this line and move to the next, instead of exiting the script…

    for {set i 0} {$i < 4} {incr i} {
        send "clear line vty $i\r"
        expect {
            "confirm]" { send "\r"; expect "*#" }
            "% Not allowed" { send "! refusing to clear line vty $i\r"; expect "*#" }
        }
    }
    

    Cisco IOS considers a line as a comment if it begins with !


    The following script logs in and clears all lines except the line the script runs on… This runs fine in my lab.

    #!/usr/bin/expect -f
    
    spawn telnet 172.16.1.5
    set user [lindex $argv 0]
    set pass [lindex $argv 1]
    
    expect "Username: "
    send "$user\r"
    expect "assword: "
    send "$pass\r"
    expect ">"
    send "enable\r"
    expect "assword: "
    send "$pass\r"
    expect "*#"
    for {set i 0} {$i < 5} {incr i} {
        send "clear line vty $i\r"
        expect {
                "confirm]" { send "\r"; expect "*#" }
                "% Not allowed" { send "! refusing to clear line vty $i\r"; expect "*#" }
        }
    }
    exit
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to using expect, and I've searched for an answer to the
I'm trying to start a new user session by creating a helper that POSTs
I would expect a Dictionary object of the form: var dict = new Dictionary<string,string>()
interval = new Date(0); return interval.getHours(); The above returns 16. I expect it to
I'm new to using VSTS and I'm trying to create some web tests to
I am pretty new to python and am using pythons SocketServer.ForkingTCPServer to create a
While connecting to the remote host using the Net::SSH::Expect module , 2 out of
Background: Up until Xcode 4.2, new projects created using any of the templates would
New Question I am looking for a way in Javascript to get the parent
New to javascript, but I'm sure this is easy. Unfortunately, most of the google

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.