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

我写的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日

      悬赏问题

      • ¥15 电脑连不上无线网络如下诊断反馈应该如何操作
      • ¥15 telegram api 使用forward_messages方法转发消息时,目标群组里面会出现此消息来源,如何隐藏?
      • ¥15 在ubuntu中无法连接到远程服务器传输文件
      • ¥15 关于#tensorflow#的问题:有没有什么方法可以让机器自己学会像素风格的图片
      • ¥15 Oracle触发器字段变化时插入指定值
      • ¥15 docker无法进入容器内部
      • ¥15 qt https 依赖openssl 静态库
      • ¥15 python flask 报错
      • ¥15 改个密码引发的项目启动问题
      • ¥100 CentOS7单线多拨