forked from xianyu110/awesome-openclaw-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebsite-monitor.sh
More file actions
59 lines (49 loc) · 1.64 KB
/
Copy pathwebsite-monitor.sh
File metadata and controls
59 lines (49 loc) · 1.64 KB
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
# 网站内容监控脚本
# 监控指定网站的内容变化,发现变化时发送通知
# 使用方法:./website-monitor.sh <url> <keyword> <notification_method>
if [ $# -lt 2 ]; then
echo "使用方法:./website-monitor.sh <url> <keyword> [notification_method]"
echo "示例:./website-monitor.sh https://example.com '新产品发布' feishu"
exit 1
fi
URL="$1"
KEYWORD="$2"
NOTIFICATION="${3:-console}"
HASH_FILE="/tmp/website-monitor-$(echo "$URL" | md5sum | cut -d' ' -f1).hash"
echo "监控网站:$URL"
echo "关键词:$KEYWORD"
echo "通知方式:$NOTIFICATION"
# 获取网页内容
CURRENT_CONTENT=$(curl -s "$URL" | grep -o "$KEYWORD" | head -1)
# 计算内容哈希
CURRENT_HASH=$(echo "$CURRENT_CONTENT" | md5sum | cut -d' ' -f1)
# 检查是否有历史记录
if [ -f "$HASH_FILE" ]; then
PREVIOUS_HASH=$(cat "$HASH_FILE")
# 比较哈希值
if [ "$CURRENT_HASH" != "$PREVIOUS_HASH" ]; then
echo "⚠ 发现变化!关键词 '$KEYWORD' 出现"
echo "时间:$(date)"
# 发送通知
case "$NOTIFICATION" in
feishu)
# 发送飞书通知
echo "发送飞书通知..."
# curl -X POST "https://open.feishu.cn/open-apis/bot/v2/hook/your-webhook" \
# -H "Content-Type: application/json" \
# -d "{\"msg_type\":\"text\",\"content\":{\"text\":\"网站 $URL 发现变化:$KEYWORD\"}}"
;;
console)
# 控制台通知
echo "📢 通知:网站 $URL 发现变化:$KEYWORD"
;;
esac
else
echo "✓ 无变化"
fi
else
echo "首次运行,建立基准"
fi
# 保存当前哈希
echo "$CURRENT_HASH" > "$HASH_FILE"