bandaoyu 2022-12-10 14:42 采纳率: 55.6%
浏览 16
已结题

我写的IP转interface的shell脚本错哪里了呢?

我写了一个ip转网口脚本,错在哪里了呢:
见:

[root@node25 xll]# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 34:73:79:17:55:aa  txqueuelen 1000  (Ethernet)
        RX packets 10196  bytes 1198536 (1.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 840  bytes 139440 (136.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xa4b00000-a4bfffff

eno2: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 34:73:79:17:55:ab  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xa4900000-a49fffff

ens3f0np0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 10:70:fd:69:af:80  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens3f1np1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.255.153.25  netmask 255.255.255.0  broadcast 10.255.153.255
        inet6 fe80::1270:fdff:fe69:af81  prefixlen 64  scopeid 0x20<link>
        ether 10:70:fd:69:af:81  txqueuelen 1000  (Ethernet)
        RX packets 2384  bytes 210953 (206.0 KiB)
        RX errors 0  dropped 71  overruns 0  frame 0
        TX packets 1698  bytes 227471 (222.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens6f0np0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 10:70:fd:5d:fc:18  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens6f1np1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.255.153.125  netmask 255.255.255.0  broadcast 10.255.153.255
        inet6 fe80::1270:fdff:fe5d:fc19  prefixlen 64  scopeid 0x20<link>
        ether 10:70:fd:5d:fc:19  txqueuelen 1000  (Ethernet)
        RX packets 641  bytes 41793 (40.8 KiB)
        RX errors 0  dropped 71  overruns 0  frame 0
        TX packets 26  bytes 1834 (1.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

上面是主机 网卡情况

这是我写的函数

function ip2eth() { ipv4=$1; eth=$(ifconfig | awk -F ":" '/'$ipv4'/{print a}{a=$1}'); echo $eth; }

然后执行:
[root@node25 xll]# ip2eth 10.255.153.25
ens3f1np1 ens6f1np1

返回的竟然是两个网口:ens3f1np1 ens6f1np1 我的脚本错在哪里了呢?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 12月18日
    • 专家修改了标签 12月10日
    • 创建了问题 12月10日

    悬赏问题

    • ¥20 c语言写的8051单片机存储器mt29的模块程序
    • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
    • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。
    • ¥50 rk3588板端推理
    • ¥250 opencv怎么去掉 数字0中间的斜杠。
    • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
    • ¥250 paddleocr带斜线的0很容易识别成9
    • ¥15 电子档案元素采集(tiff及PDF扫描图片)
    • ¥15 flink-sql-connector-rabbitmq使用
    • ¥15 zynq7015,PCIE读写延时偏大