Get the App
SLTechnology News&Howtos  ›  Servers  › 

The case of Shell scripting uses regular expressions (network configuration and dhcp configuration scripts)

Shulou Source: shulou.com Published: 2022-06-02 19:41:31 09月16日 Update

Regular expressions are used in the case of Shell scripting

1) VMware software, virtual machine is Centos7 system, use shell script to configure static network card

#! / bin/bash# the shell script is suitable for the configuration of VMware Centos7 dual Nic # author:lokott#version:2.0# below is to disable the firewall and SELinux, which can not be written here I am used to shutting down systemctl stop firewalled.service & > / dev/nullsetenforce 0 & > / dev/nullcp-p / etc/sysconfig/network-scripts/ifcfg-ens33 / etc/sysconfig/network-scripts/ifcfg-ens36# before starting the service. The var=/etc/sysconfig/network-scripts#sed command changes dhcp to static, all ens33 to ens36, and deletes the line where UUID is located. Finally, add the subnet mask of the ip address and the default gateway, sed-I's _ If not, exit ipadd= `ifconfig ens36 directly | sed-n '2p' | awk' {print $2} '`if [$ipadd! = "192.168.100.100"] then exit 1fi

2) DHCP scripting

#! / bin/bash# this script is used to configure the shell script for the dhcp service # author:lokott#version:2.0# can be used to execute the script. / dhcp.sh 2 > & 1 > / dev/nullyum install dhcp- y & > / dev/nullyum install expect-y & > / dev/nullvar1=/usr/share/doc/dhcp-4.2.5/dhcpd.conf.examplevar2=/etc/dhcp/dhcpd.conf# below is to turn off the firewall and SELinux. You don't have to write here. I am used to shutting down systemctl stop firewalled.service & > / dev/nullsetenforce 0 & > / dev/null#expect interaction-free part / usr/bin/expect before starting the service.

Tags: Script configuration service address network card firewall first will fire prevention case regular network script programming expression programming normal content variable command location time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft MariaDB Redmi Xiaomi