Skip to content

Instantly share code, notes, and snippets.

@codeout codeout/juniper.tcl
Created Jun 13, 2017

Embed
What would you like to do?
juniper.tcl
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.