Skip to content

Instantly share code, notes, and snippets.

@codeout
Created June 13, 2017 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeout/235476ec135cb29266877f78068e65bb to your computer and use it in GitHub Desktop.
Save codeout/235476ec135cb29266877f78068e65bb to your computer and use it in GitHub Desktop.
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