提醒規(guī)則
每周設(shè)置兩人值班暇藏,一個(gè)第一值班人,一個(gè)第二值班人濒蒋。腳本每天運(yùn)行一次盐碱。
配置文件:config
curr_week=28
curr_index=0
watcher_arr=(張三 李四)
watcher_phone=(180xxxx 139xxxx)
# 發(fā)送提醒接口
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"
# 如果明天的周數(shù) 等于 當(dāng)前周數(shù)
if [ $tomorrow_week -eq $curr_week ];then
first_index=$curr_index
else
first_index=$[ $curr_index + 1 ]
fi
# 判斷 第一值班人下班是否大于等于數(shù)組下標(biāo)
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}}"