
쉘 스크립트를 사용하여 다음 구성 파일을 어떻게 만들 수 있습니까? 이 파일은 사용자의 입력을 사용하여 스크립트를 사용하여 자동으로 생성되어야 합니다.
파일을 생성할 경로는/etc/sysconfig/network-scripts/ifcfg-enp0s3-range0
스크립트를 실행하는 동안 사용자는 다음 세부 정보를 제공해야 하며, 사용자로부터 세부 정보를 가져와 파일을 생성해야 합니다.
IPADDR_START=23.82.132.2
IPADDR_END=23.82.132.60
CLONENUM_START=0
GATEWAY=23.82.132.62
PREFIX=26
답변1
sudo cd /etc/sysconfig/network-scripts/
ls
원하는 텍스트 편집기를 사용하여 스크립트를 만듭니다.
#!/bin/sh
echo Enter the filename to be created
read filename
touch $filename
echo Enter the Start range of the IPADDR
read startipaddress
echo IPADDR_START=$startipaddress >> $filename
echo Enter the End range of the IPADDR
read endipaddress
echo IPADDR_END=$endipaddress >> $filename
echo Enter the Gateway address
read gateway
echo GATEWAY=$gateway >> $filename
echo Enter the Prefix value
read prefix
echo PREFIX=$prefix >> $filename
echo Enter the Cloneum value
read cloneum
echo CLONENUM_START=$clonenum >> $filename
echo “DELAY=0” >> $filename
cat /etc/sysconfig/network-scripts/$filename
systemctl restart network
생성된 파일을 실행 가능하게 만듭니다.
sudo chmod +x <filename>
그런 다음 스크립트를 실행합니다.
sudo ./<filename>