• 脚本添加删除nginx配置中的内容


    [root@nodejs script]# more editnginx.sh 
    #!/bin/bash
    #
    
    
    function back_check(){
    
    # 备份配置和覆盖配置文件
    cp -rf /etc/nginx/nginx.conf /etc/nginx/nginx.conf-$(date +%Y%m%d-%H%M%S) && 
    echo "[+] /etc/nginx/nginx.conf-$(date +%Y%m%d-%H%M%S) backup OK!"
    
    # 对比修
    diff nginx.conf /etc/nginx/nginx.conf
    
    # 覆盖线上配置
    read -p "Write nginx config File(y/n)?" inString
    if [ $inString == "y" ];then
      cp -rf nginx.conf /etc/nginx/nginx.conf
    elif [ $inString == "n"];then
      echo "Quit!!!"
      exit 1
    else
      echo "args error!!"
      exit 2
    fi
    
    nginx -t -c /etc/nginx/nginx.conf
    }
    
    
    
    # 添加节点函数
    function insert_row(){
    # 编辑配置文件
    nginx -t -c /etc/nginx/nginx.conf
    RETURN=$?
    
    if [ $RETURN == 0 ];then
    cp -rf /etc/nginx/nginx.conf nginx.conf && echo "[+] Copy nginx.conf to current directory OK!!"
    
    sed -i -n -e :a -e '1,2!{P;N;D;};N;ba' nginx.conf
    
    echo "        location ~/api/v$1 {
                proxy_pass http://127.0.0.1:60$1;
            }
        }
    }" >>nginx.conf
    
    fi
    
    back_check
    }
    
    
    
    
    
    # 删除节点函数
    function delete_row(){
       cp -rf /etc/nginx/nginx.conf nginx.conf && echo "[+] Copy nginx.conf to current directory OK!!"
       sed -i "/location ~/api/v$1/,/}/d" nginx.conf
       back_check
       #sed -n "$1p" nginx.conf
    }
    
    
    
    # 帮助选项
    function help(){
      echo -e "Usage: $(basename $0) {-h|-i|-d}
    "
    }
    
    
    if [ -z $1 ];then
      help
    fi
    
    while getopts "i:d:h" OPTIONS; do
      case ${OPTIONS} in
        i ) insert_row $OPTARG;;
        d ) delete_row $OPTARG;;
        h ) help; exit;;
      esac
    done

    # 添加

    # 删除

  • 相关阅读:
    线性表——(2)单向链表
    线性表——(1)顺序表
    UVa 1592 数据库
    UVa 12096 集合栈计算机
    Python 协程
    Python 多线程及进程
    Python 日志(Log)
    Python 函数式编程
    Python基础
    DB2 获取前两天的数据
  • 原文地址:https://www.cnblogs.com/caoguo/p/5085631.html
Copyright © 2020-2023  润新知