script
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
#!/bin/bash  

# This is the basic bash script
export LANG=zh_CN.UTF-8
request_date=`date`
request_log=/home/byzhao/baidu_log.log

echo "下载目录"

curl https://byzhao.cn/post-sitemap.xml -o /home/byzhao/output.xml

echo "解析文档....."

xpath -q -e '//url/loc/text()' /home/byzhao/output.xml | tee /home/byzhao/urls.txt

perl -p -i -e "s/endless-zby.github.io/www.byzhao.cn/g" /home/byzhao/urls.txt

echo "同步至百度收录平台....."

request_code=`curl -s -H 'Content-Type:text/plain' --data-binary @/home/byzhao/urls.txt "http://data.zz.baidu.com/urls?site=www.byzhao.cn&token=XXXXXXXXX" | jq`

echo "$request_code" >> $request_log

request_code2=`echo "$request_code" | grep success`

echo "$request_code2" >> $request_log

if [[ "$request_code2" == *success* ]]
then
request_message=`echo -e "$request_date \t 推送成功\n$request_code\n"`
echo "$request_message" >> $request_log
echo "$request_message"
# 发送消息到手机
remain=`echo $request_code | jq '.remain'`
success_no=`echo $request_code | jq '.success'`
echo "$remain" >> $request_log
message=`curl -X "POST" "http://xxxx.xxxxxx.cn:xxxx/message/push" -H 'Content-Type: application/json;charset=utf-8' -d '{"text":"百度收录同步成功","desp":"### 百度收录同步成功 \n- 剩余推送数量:'$remain' \n- 本地推送数量:'$success_no'","pushkey":"PDU1TtRhwbxSrMmJ38D4aPOduQdG82WcXOHVa"}' | jq`

echo "$message"
else
request_message=`echo -e "$request_date \t 推送异常\n$request_code\n"`
echo "$request_message" >> $request_log
echo "$request_message"
fi