【问题标题】:shell script network construction error : not found, : file name too longshell脚本网络构建错误:未找到,:文件名太长
【发布时间】:2020-07-10 09:03:59
【问题描述】:

我尝试使用 shell 脚本构建网络

但是,我收到了类似图像的错误(:未找到,:文件名太长)

我已经徘徊了几天,在哪里以及如何解决它。


#!/bin/bash

sysctl -w net.ipv4.ip_forward=1

hn=$(hostname)

echo $hn

case $hn in

"node0")

echo"

auto lo


iface lo inet loopback


auto eth0

iface eth0 inet static

address 192.168.137.8

netmask 255.255.255.0

network 192.168.137.0

gateway 192.168.137.1



auto eth1

iface eth1 inet static

address 10.0.30.9

netmask 255.255.255.0

network 10.0.30.0


gateway 10.94.30.8

">/etc/network/interfaces

;;



"node1")

echo"

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 192.168.137.9

netmask 255.255.255.0


network 192.168.137.1

gateway 192.168.137.1



auto eth1

iface eth1 inet static

address 10.94.10.8

netmask 255.255.255.0

network 10.94.10.0

gateway 10.94.10.9

">/etc/network/interfaces

;;



"node2")

echo"

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 10.94.10.9

netmask 255.255.255.0

network 10.94.10.0

gateway 10.94.10.8



auto eth1

iface eth1 inet static

address 10.94.20.8

netmask 255.255.255.0

network 10.94.20.0

gateway 10.94.20.9

">/etc/network/interfaces

;;



"node3")

echo"

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet static

address 10.94.20.9

netmask 255.255.255.0

network 10.94.20.0

gateway 10.94.20.8



auto eth1

iface eth1 inet static

address 10.94.30.8

netmask 255.255.255.0

network 10.94.30.0

gateway 10.94.30.9

">/etc/network/interfaces

;;

esac

echo"

nameserver 192.168.137.1

search localdomain

">/etc/resolv.conf

systemctl restart networking.service

【问题讨论】:

    标签: linux shell ubuntu networking network-programming


    【解决方案1】:

    我建议您使用heredoc(此处为文档)方法来创建您的输出文件,而不是echo。例如,

    "node1")
    cat << EOF > /etc/network/interfaces
    All lines from here to the line before the EOF below will be written to the file.
    ... multiple lines deleted ...
      This last line is indented by two spaces.
    EOF
    ;;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多