Create a gist now

Instantly share code, notes, and snippets.

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