Pagination, SendInteractive #194
-
Hello. Ideally would be method SendInteractive("command", "intermediate prompt", "intermediate input", "final prompt") |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
👋 hey @zaits07 package main
import (
"bytes"
"fmt"
"github.com/scrapli/scrapligo/driver/generic"
"github.com/scrapli/scrapligo/driver/options"
"time"
)
func main() {
var channelLog bytes.Buffer
d, err := generic.NewDriver(
"1.2.3.4",
options.WithTransportType("system"),
options.WithAuthNoStrictKey(),
options.WithSSHConfigFileSystem(),
options.WithChannelLog(&channelLog),
)
if err != nil {
panic(err)
}
err = d.Open()
if err != nil {
panic(err)
}
defer d.Close()
r, err := d.SendWithCallbacks("show run", []*generic.Callback{
{
Callback: func(driver *generic.Driver, s string) error {
return driver.Channel.Write([]byte(" "), false)
},
Contains: "--More--",
ResetOutput: true,
},
{
Contains: "end\n\nMYPROMPT#",
Complete: true,
},
}, 3*time.Second)
if err != nil {
panic(err)
}
fmt.Println(r.Result)
} this works on a cisco switch I have handy but with the "generic" driver (so pagination is not disabled). the "complete" callback is a bit fidgety since if if you just log right in and then execute this without the newlines before the prompt the initial buffer will have the prompt in it and it will "catch" the complete callback and the whole callback thing ill be done. you can solve this by sending some command before this such that the initial login buffer has been drained. probably would be good to fix the initial buffer containing data after login too... (I know this got addressed sorta recently in scrapli python). anyway. that should work for ya I think. |
Beta Was this translation helpful? Give feedback.
👋 hey @zaits07