我正在尝试使用执行 show 命令的 bash 编写脚本,并从 show 输出中获取每个主机名(字符串)并对其执行操作(show 命令)。
例如:
root@Router2:~$ show routers
Hostname1
Hostname2
Hostname3
我想获取每个主机名(主机名 1、主机名 2 和主机名 3)并对它们中的每一个执行操作。
这是我设法做到的:
figlet Status code
u=$(tput smul)
b=$(tput bold)
n=$(tput sgr0)
echo "${b}${u}Enter server's name${n}"
read -e server
echo ""
Routershow$=(show routers)
之后,我想从 $Routershow 输出中获取每个字符串(主机名)。我该怎么做?
谢谢
最佳答案
我通常使用 while read x
命令,其中“x”是变量名:
show routers | while read routerName
do
echo $routerName
done
关于linux - 如何从输出中获取每个字符串(主机名)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50676174/