小毛驴问答之shell脚本请求带json数据

业务爸爸:小毛驴帮我实现一个功能,我在做业务版本更新的时候需要把该主机在clb上权限改为0,要求用shell脚本实现。

小毛驴:安排!

#!/bin/sh
#
#调用腾讯云的clb api,修改指定 clb, 指定 localtion id下指定 targets 主机的权限。
# author 小毛驴
#

clb_modify_target_api_url=${ApiUrl}

function installJq() {
    if [ -f /etc/redhat-release ];then
        _OSFLAG=`cat /etc/redhat-release | awk '{print tolower($1)}'`
        if [[ ${_OSFLAG}x == 'centos'x  ]]  || [[  ${_OSFLAG}x == 'tencent'x ]] ; then
             yum  -y  -q  install jq
        fi
    elif [ -f /etc/lsb-release ];then
        _OSFLAG=`cat /etc/lsb-release | grep "DISTRIB_ID" | awk -F"=" '{print tolower($2)}'` 
        if [ ${_OSFLAG}x == "ubuntu"x ];then
            sudo apt-get -y   -q install jq
        fi
    else
        echo  "This is no CentOS and Ubuntu , 脚本目前不支持此系统 !"
        exit 1
    fi
}

which jq > /dev/null
if [ $? -gt 0 ]; then
    installJq
fi

function modify_clb_targets() {
    local region=$1
    local load_balancer_id=$2
    local listener_id=$3
    local location_id=$4
    local eni_ip=$5
    local port=$6
    local weight=$7
    generate_get_clb_post_data() {
cat <

知识点

  1. clb_modify_target_api_url 这个接口是基于腾讯云封装后的接口(golang实现,后面会把该代码分享), 接收json数据能修改对应clb下localtionId的主机权限。
  2. 用jq处理返回的json数据。

页面更新:2024-02-28

标签:脚本   小毛驴   数据   腾讯   知识点   端口   问答   接口   权限   主机   业务

1 2 3 4 5

上滑加载更多 ↓
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top