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

  • Home
  • SEARCH
  • 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 4534664
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:18:33+00:00 2026-05-21T14:18:33+00:00

I want to telnet into a Cisco router, login and execute a Tcl script

  • 0

I want to telnet into a Cisco router, login and execute a Tcl script that is locally stored in the router’s flash. This Tcl script does some processing and should return a nested hash (preferred) or a string that represents a XML document.

Is there a way to map a Tcl nested hash to a Perl nested hash, or to return a string that represents a XML document? Does Expect allow me to do any of the above, and how?

  • 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-05-21T14:18:33+00:00Added an answer on May 21, 2026 at 2:18 pm

    This expect script should take the file off the router and leave it in /tmp/xferfile.txt. It will need to be modified with the commands that actually produce the file, since I do not have those, I left placeholders for them in the script. You should be able to use Donal’s code for that.

    It’s been a while since I’ve played with expect and cisco IOS, so bear with me if this needs some debugging on your end.

    #!/usr/bin/expect
    set timeout 20
    set ip [lindex $argv 0]
    set user [lindex $argv 1]
    set password [lindex $argv 2]
    set prompt1 "Router>"
    set prompt2 "Router#"
    set prompt3 "bash\$"
    set ctrld [expr ("d" & 01xF)]
    
    spawn ssh "$user\@$ip"
    expect "Password:"
    send "$password\r";
    
    # switch to privileged EXEC level 
    expect $prompt1 { send "enable" }
    
    # ==================================================
    # Modify this line for your needs
    # ==================================================
    expect $prompt2 { send "command to print Tcl hash" }
    
    # Capture output to variable
    set results $expect_out(buffer)
    
    # leave EXEC level
    expect $prompt2 { send "exit" }
    # Command to log out of router
    expect $prompt1 { send "exit" }
    
    # Create text file on localhost
    spawn "#!/bin/bash"
    expect prompt3 { 
        send "cat > /tmp/xferfile.txt"
        sleep 5
        send $results
        send $crtld
        }
    
    expect prompt3 { send "exit" }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey i can login into telnet with telnet localhost 4242 now i want to
I want to make an etag that matches what Apache produces. How does apache
I have a Linux box and I want to be able to telnet into
I want to use a temp directory that will be unique to this build.
I currently have a link that launches a telnet link like this <h:outputLink value=telnet://1.2.3.4>
I want to provide a telnet interface to my Java application, primarily so that
I want to create a script that sends a message to another IP. Using
I want to write a C# application where it connects to a telnet server
I want to assign the decimal variable "trans" to the double variable "this.Opacity". decimal
We have a legacy system that is essentially a glorified telnet interface. We cannot

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.