-
Notifications
You must be signed in to change notification settings - Fork 38
/
docker.sh
37 lines (26 loc) · 1.46 KB
/
docker.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
#!/bin/bash
# Docker容器状态检测
#----------------------------
# 计划任务,每天20点运行脚本
# 0 20 * * * /bash/docker.sh #Docker容器状态检测
# 手动运行脚本
# /bash/docker.sh
# 添加运行权限
# chmod +x /bash/docker.sh
#----------------------------
docker=$(docker ps -a | grep Exited) && dockerstop=$(awk '{print $(2)}' <<<${docker}) && echo "$dockerstop" >> /var/tmp/dockerlist.md
# 排除项目
cat >> /var/tmp/docker.md <<EOF
hectorqin/reader
EOF
# 对比容器停止列表
docker=`grep -Fxvf /var/tmp/docker.md /var/tmp/dockerlist.md`
dockers=`echo $docker | sed 's/ /、/g'`;echo $dockers
# 如果变量有效就发送通知
if [ -n "$docker" ]; then curl "http://xxxx:xx/push?token=dahuilang&message=🚫容器意外停止,停止列表:$dockers......"; else curl "http://xxxx:xx/push?token=dahuilang&message=🎉所有容器运行正常......"; fi
# 容器出问题才发消息
# if [ -n "$docker" ]; then curl "http://xxxx:xx/push?token=dahuilang&message=🚫容器意外停止,停止列表:$dockers";fi
# if [ -n "$docker" ]; then curl "https://api-telegram.workers.dev/bot1622585953:AAxxccff/sendMessage" -d "chat_id=12345678&text=🚫容器意外停止,停止列表:$dockers......"; else curl "https://api-telegram.workers.dev/bot12345:AAGeQmivyLJjVC5xxcc/sendMessage" -d "chat_id=12345678&text=🎉所有容器运行正常......"; fi
# 删除对比更新目录列表
rm -rf /var/tmp/docker.md
rm -rf /var/tmp/dockerlist.md