美文网首页
记录-每日值班人员提醒脚本

记录-每日值班人员提醒脚本

作者: SmartBin | 来源:发表于2022-07-13 18:00 被阅读0次

    提醒规则

    每周设置两人值班,一个第一值班人,一个第二值班人。脚本每天运行一次。

    配置文件:config

    curr_week=28
    curr_index=0
    watcher_arr=(张三 李四)
    watcher_phone=(180xxxx 139xxxx)
    # 发送提醒接口
    alert_url=http://other-1:8355/alert/watcher_notice
    

    shell脚本

    #!/bin/bash
    
    PRG="$0"
    while [ -h "$PRG" ]; do
      ls=$(ls -ld "$PRG")
      link=$(expr "$ls" : '.*->  \(.*\)$')
      if expr "$link" : '.*/.*'  >/dev/null; then
        PRG="$link"
      else
        PRG=$(dirname "$PRG")/"$link"
      fi
    done
    PRGDIR=$(dirname "$PRG")
    # full path
    cd  "$PRGDIR"/
    PRGDIR=$(pwd)
    
    config_name="config"
    
    echo "$PRGDIR"
    . $PRGDIR/${config_name}
    # 值班人员提醒脚本
    
    
    tomorrow=`date -d 'tomorrow' +%Y%m%d`
    echo "tomorrow: $tomorrow"
    # 明天是第几周
    tomorrow_week=`date -d $tomorrow +%V`
    echo "curr_week: $curr_week"
    echo "curr_index: $curr_index"
    
    # 如果明天的周数 等于 当前周数
    if [ $tomorrow_week -eq $curr_week ];then
      first_index=$curr_index
    
    else
      first_index=$[ $curr_index + 1 ]
    fi
    
    # 判断 第一值班人下班是否大于等于数组下标
    if [ $first_index -ge ${#watcher_arr[*]} ];then
      first_index=0
    fi
    #第二值班人
    second_index=$[ $first_index + 1 ]
    
    # 判断下班是否越界
    if [ $second_index -ge ${#watcher_arr[*]} ];then
      second_index=0
    fi
    
    #echo "first_index : $first_index"
    #echo "${watcher_arr[${first_index}]}"
    #echo "second_index: $second_index"
    
    # 不等于
    if [ $tomorrow_week -ne $curr_week ];then
      # 更新配置文件
      echo "curr_week=$tomorrow_week" >$PRGDIR/${config_name}
      echo "curr_index=$first_index" >>$PRGDIR/${config_name}
      echo "watcher_arr=(${watcher_arr[*]})" >> $PRGDIR/${config_name}
      echo "watcher_phone=(${watcher_phone[*]})" >> $PRGDIR/${config_name}
      echo "alert_url=${alert_url}" >> $PRGDIR/${config_name}
    fi
    
    first_watcher=${watcher_arr[${first_index}]}
    second_watcher=${watcher_arr[${second_index}]}
    
    first_phone=${watcher_phone[${first_index}]}
    second_phone=${watcher_phone[${second_index}]}
    
    atList="[\"${first_phone}\",\"${second_phone}\"]"
    #ding ding
    curl  -X POST "${alert_url}" -H 'Content-Type: application/json' -d "{ \"first_watcher\": \"${first_watcher}\", \
    \"second_watcher\": \"${second_watcher}\", \"watcher_date\": \"${tomorrow}\",\"atList\":${atList}}"
    

    相关文章

      网友评论

          本文标题:记录-每日值班人员提醒脚本

          本文链接:https://www.haomeiwen.com/subject/xnjtirtx.html