vtysh批量执行命令

在使用quagga的过程中,实际有很多非交互式的场景,比如想批量做路由撤销的操作。从一个系统管理员的角度上看,希望对软路由的控制像直接在linux里写脚本一样简单方便。之前在vtysh里行执行路由撤销命令我是用expect实现的

  /usr/bin/expect -c "
    set timeout 2
    spawn $vtysh
    expect "*#*"        { send "conf t \r" }
    expect "*(config)#*" { send "router ospf \r" }
    expect "*(config-router)#*" { send "no network  $network area $area \r" }
    expect "*(config-router)#*" { send "exit  \r" }
    expect "*(config)#*" { send "exit  \r" }
    expect "*#*" { send "write memory  \r" }
    expect "*#*" { send "exit\r" }
  "

实际有更简单的方式

sudo vtysh  -c "configure terminal" -c "router ospf" -c "network  $network area $area "  -c "exit"  -c "exit" -c "write file"

这样可以简单对expect的依赖,脚本编写也更简洁。

此条目发表在OSPF分类目录。将固定链接加入收藏夹。

发表回复