tcl - Continue a while loop on current line -


i wrote script lot of commands on cisco devices. if problem occurs on sw or router , program stop, need remove lines before current line.

example:

ips.txt 169.254.0.1 169.254.0.2 169.254.0.3 <- reason, program stop here (no login or device becomes unreachable or anyway) 169.254.0.4 

after

ips.txt 169.254.0.3 <- run again after treat problem on device 169.254.0.4 

how can loop continue on same line stop without remove lines manually?

here loop part:

set f [open "ips.txt" r] set lines [split [read $f] "\n"] close $f set n [llength $lines] set 0  while { $i <= $n } {         set nl [lindex $lines $i]         set l3 [split $nl ","]         set ip_sw [lindex $l3 0]         set ip_rt [lindex $l3 1]      lot of tcl , expect commands... } 

you this:

set filename ips.txt set num_processed 0  while {...} {    # ...    if {successfully processed one} {         incr num_processed    } }  # out of while loop, remove first n lines file # assuming system has gnu sed exec sed -i.bak "1,${num_processed}d" $filename  # or tcl set fin [open $filename] set fout [open $filename.new w] set n 0 while {[gets $fin line] != -1} {     if {[incr n] <= $num_processed} continue     puts $fout $line } file link -hard $filename.bak $filename file rename -force $filename.new $filename 

Comments