zoukankan      html  css  js  c++  java
  • 我的shell脚本

    问题:在ip.lt文件中有600个IP,有3个文档模版,三个文档的名称结构都是“ip+一系列字符串”,要求:1.将600个IP分成3分,以三个模版为基础创建600个文档,名字结构与模版相同;2修改600个文档中的time和DNS Server

    编程:

    #!/bin/bash

    num=1

    while [ $num -le 600 ]

    do

            ipaddr=`sed -n "$num"p ip.lt`

            if [ $num -le 200 ];then

                    cp /home/ghost/test/192.168.107.105_66c221be-6ab2-ef53-1589-fe16877914e1_chk.xml ./backup1/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e1_chk.xml

                    sed -i 's/2014-5-29/2016-8-11/g' ./backup1/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e1_chk.xml

                    sed -i 's/DNS Servers . . . . . . . . . . . : 172.21.35.146/DNS Servers . . . . . . . . . . . : 8.8.8.8/g' ./backup1/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e1_chk.xml

            fi

            if [ $num -le 400 -a $num -gt 200 ] ;then

                    cp /home/ghost/test/192.168.98.102_66c221be-6ab2-ef53-1589-fe16877914e2_chk.xml ./backup2/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e2_chk.xml

                    sed -i 's/2014-5-31/2016-8-11/g' ./backup2/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e2_chk.xml

                    sed -i 's/DNS Servers . . . . . . . . . . . : 172.21.48.22/DNS Servers . . . . . . . . . . . : 8.8.8.8/g' ./backup2/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e2_chk.xml

            fi

            if [ $num -gt 400 ];then

                    cp /home/ghost/test/192.168.99.67_66c221be-6ab2-ef53-1589-fe16877914e3_chk.xml ./backup3/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e3_chk.xml

                    sed -i 's/2014-5-31/2016-8-11/g' ./backup3/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e3_chk.xml

                    sed -i 's/DNS Servers . . . . . . . . . . . : 172.21.35.146/DNS Servers . . . . . . . . . . . : 8.8.8.8/g' ./backup3/"$ipaddr"_66c221be-6ab2-ef53-1589-fe16877914e3_chk.xml

            fi

            num=$(($num + 1))

    done

    实验结果:查看backup1,backup2,backup3目录,如图1

                         图1

    随机挑选产生的一个文件,查看time和DNS Server,如图2和图3

                        图2

                        图3

  • 相关阅读:
    ZooKeeper详解
    数据结构与算法2——数组
    jquery复习笔记
    关于水平居中
    回顾这些日子
    阻止事件冒泡
    css导航栏
    js正则
    js事件绑定
    操作iframe
  • 原文地址:https://www.cnblogs.com/anorferde/p/5777993.html
Copyright © 2011-2022 走看看