Centos 创建bash脚本以添加额外的IP和操作系统
我试图创建这个bash脚本来添加服务器上文本文件中的IP 文件myfile.txt每行有1个IP,脚本test.sh包括Centos 创建bash脚本以添加额外的IP和操作系统,centos,Centos,我试图创建这个bash脚本来添加服务器上文本文件中的IP 文件myfile.txt每行有1个IP,脚本test.sh包括 #!/bin/bash count=0 while read line do filename=/etc/sysconfig/network-scripts/ifcfg-eth0:$count echo "DEVICE=eth0:$count\nBOOTPROTO=static\nIPADDR=$line\nNETMASK=255.255.255.255" > f
#!/bin/bash
count=0
while read line
do
filename=/etc/sysconfig/network-scripts/ifcfg-eth0:$count
echo
"DEVICE=eth0:$count\nBOOTPROTO=static\nIPADDR=$line\nNETMASK=255.255.255.255"
> filename
count=$((count+1))
done < myfile.txt
有人能告诉我我做错了什么吗,提前谢谢不要将
echo
与“DEVICE=eth0:$count\nBOOTPROTO=static\nIPADDR=$line\nNETMASK=255.255.255”
和>filename
。这3行应该是1行。另外,不要创建文件名。您真正想要的是$filename
。谢谢,这样做了,不得不将echo更改为printf,因为它没有添加新行,非常感谢
./test.sh: line 8: DEVICE=eth0:0\nBOOTPROTO=static\nIPADDR=95.211.140.235\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:1\nBOOTPROTO=static\nIPADDR=95.211.140.236\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:2\nBOOTPROTO=static\nIPADDR=95.211.140.237\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:3\nBOOTPROTO=static\nIPADDR=95.211.140.238\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:4\nBOOTPROTO=static\nIPADDR=95.211.140.239\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:5\nBOOTPROTO=static\nIPADDR=95.211.140.240\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:6\nBOOTPROTO=static\nIPADDR=95.211.140.241\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:7\nBOOTPROTO=static\nIPADDR=95.211.140.242\nNETMASK=255.255.255.255: command not found
./test.sh: line 8: DEVICE=eth0:8\nBOOTPROTO=static\nIPADDR=95.211.140.243\nNETMASK=255.255.255.255: command not found