创建bash脚本以添加额外的IP,分操作系统

时间:2015-05-19 02:48:04

标签: 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"
> filename
 count=$((count+1))
 done < myfile.txt

当我运行./test.sh时 我得到了

./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

有人可以告诉我这里做错了什么,提前谢谢

0 个答案:

没有答案