zoukankan      html  css  js  c++  java
  • shell脚本--02循环与条件

    1.修改文件中的IP

    $ ./ip.sh '8.8.8.1'
    #!/bin/bash
    #

    localIP=$(/sbin/ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|grep 8|awk '{print $2}'|tr -d "addr:")
    for
    ip in $(cat master.json |grep ip |sed 's/:/ /g'|awk '{print$2}' |sed 's/"//g'|sed 's/,//g');do if [ ${ip} == "1.1.1.1" ] then sed -i "s/${ip}/${localIP}/g" master.json elif [ ${ip} == "1.1.1.2" ] then sed -i "s/${ip}/$1/g" master.json fi done
    #!/bin/bash
    dos2unix agent.json
    
    master=1.1.1.1
    agent=1.1.1.11
    
    for ip in $(cat agent.json |grep ip |sed 's/:/ /g'|awk '{print$2}' |sed 's/"//g'|sed 's/,//g');do
        if [ ${ip} == ${master}]
        then
        echo change master   
        sed -i "s/${ip}/$1/g" agent.json
     
        elif [ ${ip} == ${agent} ]
        then
              echo change agent 
              sed -i "s/${ip}/$2/g" agent.json
        fi
    done

    2.嵌套循环

    for file in /home/../*.json
    do
        echo "$file:"
        for
           ...
        done
    done

     3.判断

    for file in /home/.../*
        if [ -d "$file" && "$file"=="taskserver" ]
        then
            echo "$file means localhost is server"
        
        elif [ -d "$file" && "$file" == "taskmaster"]
        then
            echo ""
        elif [ -d "$file" && "$file" == "env_agent"]
        then
            echo ""
        fi
    done
  • 相关阅读:
    setMasksToBounds
    CSRF跨站
    ORM: object relationship mapping
    orm查询
    图书管理系统(增删改)
    django图书管理半成品(MySQL)
    模板继承(练习测试)
    模板层(template)
    django命令(笔记,自己看的)
    django(注册→登录→主页)增强版
  • 原文地址:https://www.cnblogs.com/cevinchen/p/9410749.html
Copyright © 2011-2022 走看看