【发布时间】:2022-01-06 12:19:46
【问题描述】:
希望这是一个快速简单的方法! 我正在尝试在设备上搜索主机名,然后使用该主机名来指示通过 netmiko 发送给它的配置。 我认为我失败了,因为输出不在一条线上。 作为目前的测试,我只是尝试按如下方式打印输出:
device_name = net_connect.send_command('show running-config sys global-settings hostname')
hostname = re.search('^hostname', device_name, re.M)
print(hostname)
当我在设备上手动运行上述命令时,输出是这样的:
sys global-settings {
hostname triton.lakes.hostname.net
}
那么我是否需要调整 re.search 以考虑单独的行以仅捕获“主机名 triton.lakes.hostname.net”行?
非常感谢
【问题讨论】:
-
^不匹配,因为hostname是缩进的(即行以空格开头)。
标签: python regex search f5 netmiko