goph icon indicating copy to clipboard operation
goph copied to clipboard

Support for multiple Run() commands

Open mpenning opened this issue 2 years ago • 0 comments

In a similar vein to https://github.com/melbahja/goph/issues/13, is it possible to Run() multiple commands in a single session?

This fails with a panic on my system... a single command works just fine of course... single-command working copy, ref: route_views_go git hash 5e4bb51.

Doing this may require something similar to go-expect. Will goph support this functionality natively, or do I need a third-party library?

package main

import (
        "fmt"

        "github.com/gleich/logoru"
        "github.com/melbahja/goph"
)

func main() {

        // route-views username 'rviews' with no password
        client01, err := goph.New("rviews", "route-views.routeviews.org", goph.Password(""))
        if err != nil {
                logoru.Critical(err.Error())
        }
        defer client01.Close()

        // get the best BGP route info for 4.2.2.2
        cmdout01, err := client01.Run(fmt.Sprintf("show ip bgp %s bestpath", "4.2.2.2"))
        if err != nil {
                logoru.Critical(err.Error())
        }

        // get the best BGP route info for 8.8.8.8
        cmdout02, err := client01.Run(fmt.Sprintf("show ip bgp %s bestpath", "8.8.8.8"))
        if err != nil {
                logoru.Critical(err.Error())
        }

        logoru.Info(string(cmdout01))
        logoru.Info(string(cmdout02))
}

mpenning avatar Oct 08 '23 00:10 mpenning