#!/bin/bash
# 987402997@qq.com
# update 1591591395
export LANG=zh_CN.UTF-8
request_date=`date`
#下行网址替换为你的网站地图URL
request_url=https://www.clhuang.cn/sitemap.xml
request_urls=`curl --connect-timeout 5 -s $request_url | grep https | awk -F '<loc>' '{print $2}' | awk -F '</loc>' '{print $1}'`
#下行site替换为你的网站域名,需要与百度站长上认证的一致;token为百度站长中API提交产生的对应token值
request_code=`curl -s -H 'Content-Type:text/plain' --data-binary "$request_urls" "http://data.zz.baidu.com/urls?site=你的域名&token=你的token" | jq`
request_code2=`echo "$request_code" | grep success`
request_log=/var/log/baidu_log
if [ -n "$request_urls" ] && [[ "$request_code2" == *success* ]]
then
request_message=`echo -e "$request_date \t 推送成功\n$request_code\n$request_urls \n"`
echo "$request_message" >> $request_log
#下行为发送推送结果到邮箱,如果不清楚怎么配置请注释下行
echo "$request_message" | mail -s "百度收录|推送成功" mail@mail.com
else
request_message=`echo -e "$request_date \t 推送异常\n$request_code\n$request_urls \n"`
echo "$request_message" >> $request_log
#下行为发送推送结果到邮箱,如果不清楚怎么配置请注释下行
echo "$request_message" | mail -s "百度收录|推送异常" mail@mail.com
fi