juniper.tcl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
log_user 1 | |
set initialized 0 | |
proc init { } { | |
global prompt initialized | |
send "set cli complete-on-space on\r" | |
expect -re $prompt {} | |
set initialized 1 | |
} | |
proc run { command_text } { | |
global prompt initialized | |
set command [join [split $command_text \n] \;] | |
if !$initialized { init } | |
# handle escaped ;s in commands, and ;; and ^; | |
regsub -all {([^\\]);;} $command "\\1;\u002;" esccommand | |
regsub {^;} $esccommand "\u002;" command | |
set sep "\\1\u001" | |
regsub -all {([^\\])\;} $command "$sep" esccommand | |
set sep "\u001" | |
set commands [split $esccommand $sep] | |
set num_commands [llength $commands] | |
for {set i 0} {$i < $num_commands} { incr i} { | |
send "[lindex $commands $i]\r" | |
expect { | |
-re "^\[^\n\r *]*$prompt $" {} | |
-re "^\[^\n\r]*$prompt." { exp_continue } | |
-re "(\r\n|\n)" { exp_continue } | |
} | |
} | |
interact { | |
\x0E { return } # ^n to proceed | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment