-
Notifications
You must be signed in to change notification settings - Fork 1
/
send_robot.sh
59 lines (47 loc) · 1.22 KB
/
send_robot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
. ${send_robot_dir:=$(cd `dirname "${BASH_SOURCE[0]}"`;pwd)}/../conf_env/env.sh
. $lib/function.sh
# yum list installed jq | grep jq
args_length=$#
if [[ "${args_length}" != 2 && "${args_length}" != 3 ]]; then
echo "输入的参数数量(2或3个)不正确 ${args_length}!
1、机器人 Hook 的 Key
2、要发送的数据
3、要提醒人的手机号((逗号),分隔)【可无】
"
exit 1
fi
url="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${1} -H 'Content-Type: application/json'"
old_IFS=$IFS IFS=$'\n'
read -ra lines -d $'\0' <<< "${2}"
for line in ${lines[@]}; do
if [[ ${i:=1} = 1 ]]; then
data="<font color='warning'>${line}</font>"
else
tmp_IFS=$IFS IFS='|'
kv=(${line//:/|})
k="${kv[0]}"
v="${kv[1]}"
data+="\n>${k}:<font color='comment'>${v}</font>"
IFS=$tmp_IFS
fi
((i++))
done
IFS=$old_IFS
data="$(date +'%F %T') ${data}"
curl "${url}" -d "$(echo '{
"msgtype": "markdown",
"markdown": {
"content": "'${data}'"
}
}')"
[[ $args_length = 3 ]] && {
phone_nums="${3//,/","}"
curl "${url}" -d "$(echo '{
"msgtype": "text",
"text": {
"content": "",
"mentioned_mobile_list": ["'${phone_nums}'"]
}
}')"
}