|
|
本帖最后由 ywly 于 2020-2-16 12:00 编辑
上午说想要一个检测公网推送tg的脚本,一直没找到,看到mjj推荐的大佬脚本决定自己手撕
本人shell脚本小白,今天是第一次了解shell,写的不好请勿喷,如有错误虚心接受指点
此脚本通过两个脚本改的,再次感谢https://www.52.ht/thread-591273-1-1.html和https://raw.githubusercontent.com/yulewang/cloudflare-api-v4-ddns/master/cf-v4-ddns.sh
此脚本务必装curl和Python,代码中所有xxxxx全部改成自己的
[ol]set -o errexitset -o nounsetset -o pipefailVPS_NAME=xxxxxxtg_bot_api="xxxxxx"tg_chat_id="xxxxxx"WANIPSITE="http://icanhazip.com"WANIPFILE=$HOME/ip_$VPS_NAME.txtWAN_IP=`curl -s ${WANIPSITE}`maketext(){ time=$(date "+%Y-%m-%d-%H:%M:%S") msg_templete="***检测时间-${time}***\`新的ip:\`$WAN_IP"}teleGram_push(){ text=$(echo "${msg_templete}"|python -c 'import sys;import urllib; print(urllib.quote_plus(sys.stdin.read()))') curl -s --connect-timeout 5 --retry 2 --request GET --url 'https://api.telegram.org/bot'${tg_bot_api}'/sendMessage?chat_id='${tg_chat_id}'&text='${text}'&parse_mode=markdown' }if [ -f "$WANIPFILE" ]; thenOLD_IP=`cat $WANIPFILE` if [ "$WAN_IP" = "$OLD_IP" ]; then time=$(date "+%Y-%m-%d-%H:%M:%S") echo "${time} : WAN IP Unchanged" exit 0 else rm -rf $WANIPFILE echo "${WAN_IP}" > $WANIPFILE maketext teleGram_push fi else echo "${WAN_IP}" > $WANIPFILE maketext teleGram_pushfi[/ol]复制代码 |
|