#!/bin/bash
queryDayType() {
response=`curl -s http://timor.tech/api/holiday/info/$1`
echo "工作日API查询结果: ${response}"
code=`echo ${response} | jq .code`
if [[ "${code}" -ne 0 ]]
then
echo '查询节假日出错'
exit 0
fi
type=`echo ${response} | jq .type.type`
# bash的函数返回值只能是数字
return $((type))
}
# 检查今天是否是工作日
today=`date %Y-%m-%d`
queryDayType ${today}
type=$?
if [[ "${type}" -ne 0 ]]
then
echo "${today}不是工作日, 类型: ${type}, 不需要发送周报提醒."
exit 0
fi
# 检查明天是否是假期
tomorrow=`date -d next-day %Y-%m-%d`
queryDayType ${tomorrow}
type=$?
if [[ "${type}" -eq 0 ]]
then
echo "明天: ${tomorrow}是工作日, 类型: ${type}, 不需要发送周报提醒."
exit 0
fi
message='测试消息'
mobiles=''
exec < /home/dev/script/mobiles_week_report
while read line
do
mobiles="${mobiles}${line},"
done
mobiles=${mobiles%?}
response=`curl -s --request POST --url 'https://oapi.dingtalk.com/robot/send?access_token=xxx' --header 'Content-Type: application/json' --data "{'msgtype': 'text','at': {'isAtAll': false, 'atMobiles': [${mobiles}]},'text': {'content': \"${message}\"}}"`
echo "请求钉钉返回: $response"