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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:35:50+00:00 2026-06-17T13:35:50+00:00

i run a tcl send expect script in a file and execute as ./file

  • 0

i run a tcl send expect script in a file and execute as ./file

#!/usr/bin/expect
spawn -noecho telnet 42.0.1.11
set timeout 900
expect "login:"
send "admin\r"
expect "Password: "
send "ram\r"
expect "#"
for {set i 0} {$i <= 1000000000} {incr i} {
 some router commands
}

this works fine until router reloads, when router reloads, this script stops as spawn id not open., i want to resume the script (i dont know exactly how much time it takes to reload as it varies most of time).,is there any way to resume the script automatically

Thanks

  • 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-17T13:35:51+00:00Added an answer on June 17, 2026 at 1:35 pm

    Wrap your login procedure into a proc and call it again if you get EOF. Here is the basic idea, just remember that there may be other ways for things to go wrong.

    Edit: I have rewritten the code after some investigation. This has been tested on Linux with “router reboot” being simulated by Solaris 10 workstation (sorry no Cisco to reboot here). As I mentioned ping implementations differ from OS to OS so proc Ping may need to be changed to accommodate your situation.

    #!/usr/bin/tclsh
    
    package require Expect
    
    proc RouterLogin {ip user pass} {
        spawn -noecho telnet $ip
        set timeout 60
        expect "login:"
        send "$user\r"
        expect "Password: "
        send "$pass\r"
        expect "#"
        return $spawn_id
    }
    
    proc RouterPing ip {
        # ping retry limit      - 3
        # delay between retries - 30 seconds
        set limit   3
        set delay   30
        set attempt 1
        set result false
        while {$result == false && $attempt <= $limit} {
            set result [Ping $ip]
            incr attempt
            if {!$result && $attempt <= $limit} {
                # wait $delay seconds
                after [expr {1000 * $delay}]
            }
        }
        return $result
    }
    
    proc Ping ip {
        set pingCmd "ping -c 1 $ip"
        catch {eval exec $pingCmd} pingRes
        if {[regexp "bytes from" $pingRes]} {
            return true
        } else {
            return false
        }
    }
    
    proc RouterExec {ip user pass commandList} {
        set spawn_id [RouterLogin $ip $user $pass]
        set timeout 30
        foreach cmd $commandList {
            send "$cmd\r"
            expect {
                "#" {
                    # you are good
                    puts "Command executed successfully"
                }
                eof {
                    # wait 5 minutes
                    after [expr {1000 * 60 * 5}]
                    if {[RouterPing $ip]} {
                        # ping was successful, relogin and resume
                        set spawn_id [RouterLogin $ip $user $pass]
                    } else {
                        # ping was not successful, abort execution
                        return false
                    }
                }
                timeout {
                    puts "INF: timeout"
                    return false
                }
            }
        }
        send "logout\r"
        return true
    }
    
    set commandList [list command1 command2 command3]
    
    RouterExec "42.0.1.11" "admin" "ram" $commandList
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to run a program( a stemmer with a tcl file) to read
I am trying to run a csh script from a tcl script. The tcl
If we run a shell/perl/tcl script in Unix how can we display the percentage
I am a newcomer to tcl/tk and need to run a script in cadence's
I have two tcl scripts. I want to run the second script when the
I run the following command to link the different files in my project. /opt/gcc-4.7-cilkplus/bin/gcc
I run this code here <html> <script type=text/javascript src=lib/jquery-ui-1.8.21.custom.min.js></script> <script src=http://127.0.0.1:5984/_utils/script/jquery.couch.js></script> <!--<script type=text/javascript src=lib/jquery-1.7.2.js></script>-->
To run the spec files & assets as coffee script, I decided to go
I wrote a script in tcl to grab links out of the download portion
Currently I have some code that is doing an SFTP via expect/tcl. Its something

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.