原 Padavan 路由器微信推送工具 ServerChan[Server 酱] 已限制免费用户单日次数。现把脚本改成自建个人 Bark 推送,用起来一样舒服。能自定义:信息分组、角标、不同铃声。
- 需自有域名
- 需自有主机
- 需 Docker 部署
新代码
#!/bin/bash
# 此脚本路径:/etc/storage/serverchan_script.sh
# 自定义设置 - 脚本 - 自定义 Crontab 定时任务配置,可自定义启动时间
source /etc/storage/script/init.sh
export PATH='/etc/storage/bin:/tmp/script:/etc/storage/script:/opt/usr/sbin:/opt/usr/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin'
export LD_LIBRARY_PATH=/lib:/opt/lib
serverchan_enable=`nvram get serverchan_enable`
serverchan_enable=${serverchan_enable:-"0"}
serverchan_sckey=`nvram get serverchan_sckey`
serverchan_notify_1=`nvram get serverchan_notify_1`
serverchan_notify_2=`nvram get serverchan_notify_2`
serverchan_notify_3=`nvram get serverchan_notify_3`
serverchan_notify_4=`nvram get serverchan_notify_4`
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
mkdir -p /tmp/var
resub=1
# 获得外网地址
arIpAddress() {
curltest=`which curl`
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
#wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://myip.ipip.net" | grep "当前 IP" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
#wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "ip.3322.net" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
#wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://ddns.oray.com/checkip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
else
#curl -L --user-agent "$user_agent" -s "http://myip.ipip.net" | grep "当前 IP" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
curl -L --user-agent "$user_agent" -s "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
#curl -L --user-agent "$user_agent" -s ip.3322.net | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
#curl -L --user-agent "$user_agent" -s http://ddns.oray.com/checkip | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
fi
}
arIpAddress6 () {
# IPv6地址获取
# 因为一般ipv6没有nat ipv6的获得可以本机获得
#ifconfig $(nvram get wan0_ifname_t) | awk '/Global/{print $3}' | awk -F/ '{print $1}'
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "https://[2606:4700:4700::1002]/cdn-cgi/trace" | awk -F= '/ip/{print $2}'
#wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "https://ipv6.icanhazip.com"
else
curl -6 -L --user-agent "$user_agent" -s "https://[2606:4700:4700::1002]/cdn-cgi/trace" | awk -F= '/ip/{print $2}'
#curl -6 -L --user-agent "$user_agent" -s "https://ipv6.icanhazip.com"
fi
}
# 读取最近外网地址
lastIPAddress() {
inter="/etc/storage/lastIPAddress"
touch $inter
cat $inter
}
lastIPAddress6() {
inter="/etc/storage/lastIPAddress6"
touch $inter
cat $inter
}
while [ "$serverchan_enable" = "1" ];
do
serverchan_enable=`nvram get serverchan_enable`
serverchan_enable=${serverchan_enable:-"0"}
serverchan_sckey=`nvram get serverchan_sckey`
serverchan_notify_1=`nvram get serverchan_notify_1`
serverchan_notify_2=`nvram get serverchan_notify_2`
serverchan_notify_3=`nvram get serverchan_notify_3`
serverchan_notify_4=`nvram get serverchan_notify_4`
curltest=`which curl`
ping_text=`ping -4 223.5.5.5 -c 1 -w 2 -q`
ping_time=`echo $ping_text | awk -F '/' '{print $4}'| awk -F '.' '{print $1}'`
ping_loss=`echo $ping_text | awk -F ', ' '{print $3}' | awk '{print $1}'`
if [ ! -z "$ping_time" ] ; then
echo "ping:$ping_time ms 丢包率:$ping_loss"
else
echo "ping:失效"
fi
if [ ! -z "$ping_time" ] ; then
echo "online"
if [ "$serverchan_notify_1" = "1" ] || [ "$serverchan_notify_1" = "3" ] ; then
hostIP=$(arIpAddress)
hostIP=`echo $hostIP | head -n1 | cut -d' ' -f1`
if [ "$hostIP"x = "x" ] ; then
curltest=`which curl`
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "ip.3322.net" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://myip.ipip.net" | grep "当前 IP" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://ddns.oray.com/checkip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
else
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s ip.3322.net | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s "http://myip.ipip.net" | grep "当前 IP" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s http://ddns.oray.com/checkip | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
fi
fi
lastIP=$(lastIPAddress)
if [ "$lastIP" != "$hostIP" ] && [ ! -z "$hostIP" ] ; then
sleep 60
hostIP=$(arIpAddress)
hostIP=`echo $hostIP | head -n1 | cut -d' ' -f1`
lastIP=$(lastIPAddress)
fi
if [ "$lastIP" != "$hostIP" ] && [ ! -z "$hostIP" ] ; then
logger -t "【IP 变动】" "老 IPv4:${lastIP}"
logger -t "【IP 变动】" "新 IPv4:${hostIP}"
#
#默认推送等级【亮屏 active,亮屏+时效 timeSensitive,不亮屏+通知栏 passive】
#
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=【IP 变动】&body=前:${lastIP},后:${hostIP}&sound=shake&level=timeSensitive" &
logger -t "【推送服务】" "IP 变动:【${hostIP}】"
echo -n $hostIP > /etc/storage/lastIPAddress
fi
fi
if [ "$serverchan_notify_1" = "1" ] || [ "$serverchan_notify_1" = "3" ] ; then
hostIP6=$(arIpAddress6)
hostIP6=`echo $hostIP6 | head -n1 | cut -d' ' -f1`
lastIP6=$(lastIPAddress6)
if [ "$lastIP6" != "$hostIP6" ] && [ ! -z "$hostIP6" ] ; then
logger -t "【IP 变动】" "目前 IPv6:${hostIP6}"
logger -t "【IP 变动】" "上次 IPv6:${lastIP6}"
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=【IP 变动】&body=前:${lastIP6},后:${hostIP6}&sound=shake&level=timeSensitive" &
logger -t "【推送服务】" "IP 变动:${hostIP6}"
echo -n $hostIP > /etc/storage/lastIPAddress6
fi
fi
if [ "$serverchan_notify_2" = "1" ] ; then
# 获取接入设备名称
touch /tmp/var/newhostname.txt
echo "接入设备名称" > /tmp/var/newhostname.txt
#cat /tmp/syslog.log | grep 'Found new hostname' | awk '{print $7" "$8}' >> /tmp/var/newhostname.txt
cat /tmp/static_ip.inf | grep -v '^$' | awk -F "," '{ if ( $6 == 0 ) print "("$1") ("$3") ("$2")"}' >> /tmp/var/newhostname.txt
# 读取以往接入设备名称
touch /etc/storage/hostname.txt
[ ! -s /etc/storage/hostname.txt ] && echo "接入设备名称" > /etc/storage/hostname.txt
# 获取新接入设备名称
awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复.txt
if [ -s "/tmp/var/newhostname不重复.txt" ] ; then
content=`cat /tmp/var/newhostname不重复.txt | grep -v '^$'`
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=【新设备】&body=${content}&sound=shake&level=timeSensitive" &
logger -t "【推送服务】" "[新设备]${content}"
cat /tmp/var/newhostname不重复.txt | grep -v '^$' >> /etc/storage/hostname.txt
fi
fi
if [ "$serverchan_notify_4" = "1" ] ; then
# 设备上、下线提醒
# 获取接入设备名称
touch /tmp/var/newhostname.txt
echo "接入设备名称" > /tmp/var/newhostname.txt
#cat /tmp/syslog.log | grep 'Found new hostname' | awk '{print $7" "$8}' >> /tmp/var/newhostname.txt
cat /tmp/static_ip.inf | grep -v '^$' | awk -F "," '{ if ( $6 == 0 ) print "("$1") ("$3") ("$2")"}"}' >> /tmp/var/newhostname.txt
# 读取以往上线设备名称
touch /etc/storage/hostname_上线.txt
[ ! -s /etc/storage/hostname_上线.txt ] && echo "接入设备名称" > /etc/storage/hostname_上线.txt
# 上线
awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行_上线.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复_上线.txt
if [ -s "/tmp/var/newhostname不重复_上线.txt" ] ; then
content=`cat /tmp/var/newhostname不重复_上线.txt | grep -v '^$'`
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=【上线】&body=${content}&sound=shake&level=passive" &
logger -t "【推送服务】" "[上线]${content}"
cat /tmp/var/newhostname不重复_上线.txt | grep -v '^$' >> /etc/storage/hostname_上线.txt
fi
# 下线
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname.txt /etc/storage/hostname_上线.txt > /tmp/var/newhostname不重复_下线.txt
if [ -s "/tmp/var/newhostname不重复_下线.txt" ] ; then
content=`cat /tmp/var/newhostname不重复_下线.txt | grep -v '^$'`
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=【下线】&body=${content}&sound=shake&level=passive" &
logger -t "【推送服务】" "[下线]${content}"
cat /tmp/var/newhostname.txt | grep -v '^$' > /etc/storage/hostname_上线.txt
fi
fi
if [ "$serverchan_notify_3" = "1" ] && [ "$resub" = "1" ] ; then
# 固件更新提醒
[ ! -f /tmp/var/osub ] && echo -n `nvram get firmver_sub` > /tmp/var/osub
rm -f /tmp/var/nsub
wgetcurl.sh "/tmp/var/nsub" "$hiboyfile/osub" "$hiboyfile2/osub"
[[ "$(cat /tmp/var/nsub | wc -c)" -ge 20 ]] && echo "" /tmp/var/nsub
[ ! -z "$(cat /tmp/var/nsub | grep '<' | grep '>')" ] && echo "" > /tmp/var/nsub
if [ "$(cat /tmp/var/osub |head -n1)"x != "$(cat /tmp/var/nsub |head -n1)"x ] && [ -f /tmp/var/nsub ] ; then
echo -n `nvram get firmver_sub` > /tmp/var/osub
content="新固件:`cat /tmp/var/nsub | grep -v "^$"`,老固件:`cat /tmp/var/osub | grep -v "^$"` "
logger -t "【推送服务】" "固件更新:${content}"
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=【固件】&body=${content}&sound=shake&level=passive" &
echo -n `cat /tmp/var/nsub | grep -v '^$'` > /tmp/var/osub
fi
fi
resub=`expr $resub + 1`
[ "$resub" -gt 360 ] && resub=1
else
echo "Internet down 互联网断线"
resub=1
fi
sleep 30
continue
done
AI 优化版
#!/bin/bash
# 此脚本路径:/etc/storage/serverchan_script.sh
# 自定义设置 - 脚本 - 自定义 Crontab 定时任务配置,可自定义启动时间
source /etc/storage/script/init.sh
export PATH='/etc/storage/bin:/tmp/script:/etc/storage/script:/opt/usr/sbin:/opt/usr/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin'
export LD_LIBRARY_PATH=/lib:/opt/lib
serverchan_enable=`nvram get serverchan_enable`
serverchan_enable=${serverchan_enable:-"0"}
serverchan_sckey=`nvram get serverchan_sckey`
serverchan_notify_1=`nvram get serverchan_notify_1`
serverchan_notify_2=`nvram get serverchan_notify_2`
serverchan_notify_3=`nvram get serverchan_notify_3`
serverchan_notify_4=`nvram get serverchan_notify_4`
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36'
mkdir -p /tmp/var
resub=1
# 获得外网地址
arIpAddress() {
curltest=`which curl`
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
else
curl -L --user-agent "$user_agent" -s "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1
fi
}
arIpAddress6 () {
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "https://[2606:4700:4700::1002]/cdn-cgi/trace" | awk -F= '/ip/{print $2}'
else
curl -6 -L --user-agent "$user_agent" -s "https://[2606:4700:4700::1002]/cdn-cgi/trace" | awk -F= '/ip/{print $2}'
fi
}
# 读取最近外网地址
lastIPAddress() {
inter="/etc/storage/lastIPAddress"
touch $inter
cat $inter
}
lastIPAddress6() {
inter="/etc/storage/lastIPAddress6"
touch $inter
cat $inter
}
while [ "$serverchan_enable" = "1" ];
do
serverchan_enable=`nvram get serverchan_enable`
serverchan_enable=${serverchan_enable:-"0"}
serverchan_sckey=`nvram get serverchan_sckey`
serverchan_notify_1=`nvram get serverchan_notify_1`
serverchan_notify_2=`nvram get serverchan_notify_2`
serverchan_notify_3=`nvram get serverchan_notify_3`
serverchan_notify_4=`nvram get serverchan_notify_4`
curltest=`which curl`
ping_text=`ping -4 223.5.5.5 -c 1 -w 2 -q`
ping_time=`echo $ping_text | awk -F '/' '{print $4}'| awk -F '.' '{print $1}'`
ping_loss=`echo $ping_text | awk -F ', ' '{print $3}' | awk '{print $1}'`
if [ ! -z "$ping_time" ] ; then
echo "开始 Ping:$ping_time ms,丢包率:$ping_loss"
else
echo "开始 Ping:失效"
fi
if [ ! -z "$ping_time" ] ; then
echo "Online 正处于在线状态!"
if [ "$serverchan_notify_1" = "1" ] || [ "$serverchan_notify_1" = "3" ] ; then
hostIP=$(arIpAddress)
hostIP=`echo $hostIP | head -n1 | cut -d' ' -f1`
if [ "$hostIP"x = "x" ] ; then
curltest=`which curl`
if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "ip.3322.net" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://myip.ipip.net" | grep "现在 IP" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`wget -T 5 -t 3 --user-agent "$user_agent" --quiet --output-document=- "http://ddns.oray.com/checkip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
else
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s "http://members.3322.org/dyndns/getip" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s ip.3322.net | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s "http://myip.ipip.net" | grep "现在 IP" | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
[ "$hostIP"x = "x" ] && hostIP=`curl -L --user-agent "$user_agent" -s http://ddns.oray.com/checkip | grep -E -o '([0-9]+\.){3}[0-9]+' | head -n1 | cut -d' ' -f1`
fi
fi
lastIP=$(lastIPAddress)
if [ "$lastIP" != "$hostIP" ] && [ ! -z "$hostIP" ] ; then
sleep 60
hostIP=$(arIpAddress)
hostIP=`echo $hostIP | head -n1 | cut-d' ' -f1`
lastIP=$(lastIPAddress)
fi
if [ "$lastIP" != "$hostIP" ] && [ ! -z "$hostIP" ] ; then
logger -t "【IP 变动】" "老 IP:${lastIP}"
logger -t "【IP 变动】" "新 IP:${hostIP}"
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=[IP 变动]&body=老【:${lastIP}】,新【${hostIP}】&group=网络信息&sound=shake" &
logger -t "【系统PUSH】" "IP 变动:【${hostIP}】"
echo -n $hostIP > /etc/storage/lastIPAddress
fi
fi
if [ "$serverchan_notify_1" = "1" ] || [ "$serverchan_notify_1" = "3" ] ; then
hostIP6=$(arIpAddress6)
hostIP6=`echo $hostIP6 | head -n1 | cut -d' ' -f1`
lastIP6=$(lastIPAddress6)
if [ "$lastIP6" != "$hostIP6" ] && [ ! -z "$hostIP6" ] ; then
logger -t "【IP 变动】" "老 IP:${lastIP6}"
logger -t "【IP 变动】" "新 IP:${hostIP6}"
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=[IP 变动]&body=老【:${lastIP6}】,新【${hostIP6}】&group=网络信息&sound=shake" &
logger -t "【系统PUSH】" "IP 变动:【${hostIP6}】"
echo -n $hostIP > /etc/storage/lastIPAddress6
fi
fi
if [ "$serverchan_notify_2" = "1" ] ; then
touch /tmp/var/newhostname.txt
echo "接入设备名称" > /tmp/var/newhostname.txt
cat /tmp/static_ip.inf | grep -v '^$' | awk -F "," '{ if ( $6 == 0 ) print "("$2" "$1" "$3")"}' >> /tmp/var/newhostname.txt
touch /etc/storage/hostname.txt
[ ! -s /etc/storage/hostname.txt ] && echo "接入设备名称" > /etc/storage/hostname.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复.txt
if [ -s "/tmp/var/newhostname不重复.txt" ] ; then
content=`cat /tmp/var/newhostname不重复.txt | grep -v '^$'`
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=[新设备]&body=${content}&group=设备信息&sound=shake" &
logger -t "【系统PUSH】" "[新设备]${content}"
cat /tmp/var/newhostname不重复.txt | grep -v '^$' >> /etc/storage/hostname.txt
fi
fi
if [ "$serverchan_notify_4" = "1" ] ; then
touch /tmp/var/newhostname.txt
echo "接入设备名称" > /tmp/var/newhostname.txt
cat /tmp/static_ip.inf | grep -v '^$' | awk -F "," '{ if ( $6 == 0 ) print "("$2" "$1" "$3")"}' >> /tmp/var/newhostname.txt
touch /etc/storage/hostname_上线.txt
[ ! -s /etc/storage/hostname_上线.txt ] && echo "接入设备名称" > /etc/storage/hostname_上线.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行_上线.txt
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复_上线.txt
if [ -s "/tmp/var/newhostname不重复_上线.txt" ] ; then
content=`cat /tmp/var/newhostname不重复_上线.txt | grep -v '^$'`
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=[上线]&body=${content}&group=在线信息&sound=shake" &
logger -t "【系统PUSH】" "[上线]${content}"
cat /tmp/var/newhostname不重复_上线.txt | grep -v '^$' >> /etc/storage/hostname_上线.txt
fi
awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname.txt /etc/storage/hostname_上线.txt > /tmp/var/newhostname不重复_下线.txt
if [ -s "/tmp/var/newhostname不重复_下线.txt" ] ; then
content=`cat /tmp/var/newhostname不重复_下线.txt | grep -v '^$'`
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=[下线]&body=${content}&group=离线信息&sound=shake" &
logger -t "【系统PUSH】" "[下线]${content}"
cat /tmp/var/newhostname.txt | grep -v '^$' > /etc/storage/hostname_上线.txt
fi
fi
if [ "$serverchan_notify_3" = "1" ] && [ "$resub" = "1" ] ; then
[ ! -f /tmp/var/osub ] && echo -n `nvram get firmver_sub` > /tmp/var/osub
rm -f /tmp/var/nsub
wgetcurl.sh "/tmp/var/nsub" "$hiboyfile/osub" "$hiboyfile2/osub"
[[ "$(cat /tmp/var/nsub | wc -c)" -ge 20 ]] && echo "" /tmp/var/nsub
[ ! -z "$(cat /tmp/var/nsub | grep '<' | grep '>')" ] && echo "" > /tmp/var/nsub
if [ "$(cat /tmp/var/osub |head -n1)"x != "$(cat /tmp/var/nsub |head -n1)"x ] && [ -f /tmp/var/nsub ] ; then
echo -n `nvram get firmver_sub` > /tmp/var/osub
content="新固件: `cat /tmp/var/nsub | grep -v '^$'` ,旧固件: `cat /tmp/var/osub | grep -v '^$'` "
curl -L -s "https://xxxxxx.com/$serverchan_sckey" -d "title=[固件]&body=${content}&group=固件信息&sound=shake" &
logger -t "【系统PUSH】" "固件提醒:${content}"
echo -n `cat /tmp/var/nsub | grep -v '^$'` > /tmp/var/osub
fi
fi
resub=`expr $resub + 1`
[ "$resub" -gt 360 ] && resub=1
else
echo "Internet down 互联网断线"
resub=1
fi
sleep 30
continue
done
- 脚本
https://自己域名.com/
需修改。 - 路由器后台设置推送界面
SCKEY
需填写 iOS Bark 生成的那串代码即可。 - 2023-9-21 更新适配版本 23-09-1。
- 2023-10-8 更新 AI 优化版。
- 2023-10-18 只支持最后固件 3.4.3.9-099_23-08-3,后续脚本更新会导致脚本无法使用。
2023-10-19 关于离线设备检测不及时,可能用到的代码方案:
更新 2023-10-19