sh name.sh yuming.txt yuming_bak.txtios
for name in `cat $1`bash
dodom
echo "www.$name||:80:www.$name,:80:$name||d:\wwwroot\www.$name" >> $2ide
doneorm
注:$1是保存要修改的文件名,$2修改後保存的文件名ip
[root@nagios_client1 domain]# cat modify.sh input
#!/usr/bin/bash域名
file_number=`ls /root/domain/*.txt|wc -l`it
#echo $file_numberio
for i in `ls /root/domain/*.txt`
do
[ ${i##*-} == "1.txt" ] && sh /root/domain/name.sh ${i} ${i}_bak || sh /root/domain/name2.sh ${i} ${i}_bak
done
注:[ ${i##*-} == "1.txt" ] #以判斷文件名執行相關腳本
格式化域名和IP解析格式
cat jiexi.sh
#!/usr/bin/bash
path="/root/domain/"
read -p "please input file name number:" file_number
read -p "please input ip before 3 number like:192.168.1:" ip_number
#echo $file_number
#echo $ip_number
cat /root/domain/${file_number}-1.txt > /root/domain/${file_number}_yuming
echo "" >> ${path}${file_number}_yuming
cat /root/domain/${file_number}-2.txt >> /root/domain/${file_number}_yuming
seq -f "${ip_number}.%01g" 3 252 > ${path}${file_number}_ip
#echo "" >> ${path}${file_number}_ip
seq -f "${ip_number}.%01g" 3 252 >> ${path}${file_number}_ip
n=1
ip_line=`cat ${path}${file_number}_ip|wc -l`
while [ ${n} -le ${ip_line} ]
do
ym=`sed -n "${n},${n}p" ${path}${file_number}_yuming` && ip=`sed -n "${n},${n}p" ${path}${file_number}_ip`
echo "${ym},${ip}" >> ${path}${file_number}_format
let n+=1
done
能夠簡單點,去掉while循環代碼,使用:
paste -d , ${path}${file_number}_yuming ${path}${file_number}_ip >> ${path}${file_number}_format