I have device configuration saved in a file and use it to configure through vtysh.
config,err := ioutil.ReadFile(filePath)
if err != nil {
fmt.Println("Read err:")
fmt.Println(err)
os.Exit(1)
}
cmd := exec.Command("vtysh", "-c", "configure terminal", "-c",string(config))
out, err := cmd.CombinedOutput()
if err != nil {
fmt.Println("vtysh err:")
fmt.Println(err)
return
} else {
fmt.Println(out)
}
Above code gives error:
vtysh err:
exit status 1
File contents :
vlan 1
no shutdown
vlan 999
no shutdown
If I paste the file contents into vtysh( config terminal context) then the commands do execute.
The vtysh commands that I'm trying to run:
switch# configure terminal
switch(config)# vlan 89
switch(config-vlan)# no shut
switch(config-vlan)# vlan 90
switch(config-vlan)# no shut