linux - 协助解决 bash、shell 脚本语法错误

标签 linux

一位前网络工程师正在使用 Xymon 进行节点监控。该 shell 脚本之前用于将主动监控的节点与核心交换机的路由表进行比较,并相应地输出数据以显示任何新网络。

尝试执行 shell 脚本现在返回错误:

    awk: cmd. line:1: warning: escape sequence `\.' treated as plain `.'

以下是应用于 shell 脚本的命令:

    cat /var/lib/rancid/dnow/configs/ushouston-dnw1-cr01 | awk '/display ip routing-table/{flag=1;next}/display vlan all/{flag=0}f$
    ROUTELIST=$(grep -E "\.0/2[2,3,4]" /tmp/routes.txt | grep -v 192.168.13.1 | awk '{print $2}' | awk -F. '{print $1"\."$2"\."$3}$
    for ROUTE in $ROUTELIST ; do
            CHECK=$(grep -w $ROUTE /etc/hosts)
            if [ "$CHECK" = "" ] ; then
                    echo "$ROUTE is not monitored"
            fi
    done

非常感谢任何帮助或指导了解为什么会收到错误以及需要调整哪些内容。

编辑:我没有提到这是一个 Linux 系统,内核版本 3.16.0-44-generic。

最佳答案

警告来自于此:

{print $1"\."$2"\."$3}

普通字符串中不需要转义 .,只需在正则表达式中转义即可。应该是:

{print $1"."$2"."$3}

关于linux - 协助解决 bash、shell 脚本语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53272156/

相关文章:

linux -/dev/bus/usb 未创建/未找到

linux - KDE 4.2 上的 wxPython : popping window on top of the screen and hiding back

Java IOException : Permission denied on linux while running as owner 错误

linux - 在 Linux 中从网络摄像头获取视频流

java - 从 linux 命令行生成覆盖率报告

linux - 您将如何在 WSL2 上运行的 ubuntu 中正确安装 MATLAB?

linux - 从 Linux 中的多个文件中删除文本行

linux - 使用 Vagrant shell provisioner 安装 NodeJS 不工作

linux - GDB - 汇编程序返回/bin/sh : 0: Can't open �

linux - .so补丁RedHat和Ubuntu之间的版本差异