简体   繁体   English

在bash脚本中使用多个列变量从路由器提取输出

[英]Use multiple column variables in bash script to pull output from routers

I have a script that logs on to routers and pulls output that is named routerauto. 我有一个脚本登录到路由器并提取名为routerauto的输出。 I would like to use data from a text file to automatically populate required commands to pull required info from a large number of routers. 我想使用文本文件中的数据自动填充所需的命令,以从大量路由器中提取所需的信息。

Ultimately I would like the script to move through each line of the text file, filling in the gaps with the output from the columns as below. 最终,我希望脚本在文本文件的每一行中移动,用下面各列的输出填充空白。 The text file uses tab as separator. 文本文件使用制表符作为分隔符。

routerauto VARIABLE1 "sh service id VARIABLE2 sap VARIABLE4 detail"

Example data: 示例数据:

hostnamei       serv-id cct             sap
london-officei  123456  No987654321     8/1/4:100

Example output: 输出示例:

routerauto london-office "sh service id 123456 sap 8/1/4:100 detail"

Here is a bash only solution: 这是仅限bash解决方案:

#!/bin/bash

while read hostnamei servid cct sap; do
    echo routerauto $hostnamei \"sh service id $servid sap $sap detail\"
done < <(tail -n +2 sample.data)

Producing given your sample file: 给定您的示例文件:

routerauto london-officei "sh service id 123456 sap 8/1/4:100 detail"

Please note this assume no space are allowed in your various data fields. 请注意,这假设您的各种数据字段中均不允许有空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM