找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 3968|回复: 5

微信延时推送(网卡休眠问题)

[复制链接]
发表于 2017-5-2 23:39 | 显示全部楼层 |阅读模式
本帖最后由 Xianun 于 2017-5-2 23:39 编辑

脚本基于4-28,默认延时10分钟(可自己修改延时时间,代码113行,将10改成其他数字即可),下线通知不是实时,大家根据自己情况使用。若各位大神有更好的解决方案,希望也分享一下,谢谢!
  1. #!/bin/sh
  2. # 此脚本路径:/etc/storage/serverchan_script.sh
  3. # 自定义设置 - 脚本 - 自定义 Crontab 定时任务配置,可自定义启动时间
  4. source /etc/storage/script/init.sh
  5. export PATH='/opt/usr/sbin:/opt/usr/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin'
  6. export LD_LIBRARY_PATH=/lib:/opt/lib
  7. serverchan_enable=`nvram get serverchan_enable`
  8. serverchan_enable=${serverchan_enable:-"0"}
  9. serverchan_sckey=`nvram get serverchan_sckey`
  10. serverchan_notify_1=`nvram get serverchan_notify_1`
  11. serverchan_notify_2=`nvram get serverchan_notify_2`
  12. serverchan_notify_3=`nvram get serverchan_notify_3`
  13. serverchan_notify_4=`nvram get serverchan_notify_4`
  14. mkdir -p /tmp/var
  15. resub=1
  16. count=0
  17. # 获得外网地址
  18.     arIpAddress() {
  19.     curltest=`which curl`
  20.     if [ -z "$curltest" ] || [ ! -s "`which curl`" ] ; then
  21.         wget --no-check-certificate --quiet --output-document=- "http://members.3322.org/dyndns/getip"
  22.         #wget --no-check-certificate --quiet --output-document=- "1212.ip138.com/ic.asp" | grep -E -o '([0-9]+\.){3}[0-9]+'
  23.         #wget --no-check-certificate --quiet --output-document=- "ip.6655.com/ip.aspx"
  24.         #wget --no-check-certificate --quiet --output-document=- "ip.3322.net"
  25.     else
  26.         curl -k -s "http://members.3322.org/dyndns/getip"
  27.         #curl -k -s 1212.ip138.com/ic.asp | grep -E -o '([0-9]+\.){3}[0-9]+'
  28.         #curl -k -s ip.6655.com/ip.aspx
  29.         #curl -k -s ip.3322.net
  30.     fi
  31.     }
  32. # 读取最近外网地址
  33.     lastIPAddress() {
  34.         local inter="/etc/storage/lastIPAddress"
  35.         cat $inter
  36.     }

  37. while [ "$serverchan_enable" = "1" ];
  38. do
  39. serverchan_enable=`nvram get serverchan_enable`
  40. serverchan_enable=${serverchan_enable:-"0"}
  41. serverchan_sckey=`nvram get serverchan_sckey`
  42. serverchan_notify_1=`nvram get serverchan_notify_1`
  43. serverchan_notify_2=`nvram get serverchan_notify_2`
  44. serverchan_notify_3=`nvram get serverchan_notify_3`
  45. serverchan_notify_4=`nvram get serverchan_notify_4`
  46. curltest=`which curl`
  47. if [ -z "$curltest" ] ; then
  48.     wget --continue --no-check-certificate -s -q -T 10 http://www.163.com
  49.     [ "$?" == "0" ] && check=200 || check=404
  50. else
  51.     check=`curl -k -s -w "%{http_code}" "http://www.163.com" -o /dev/null`
  52. fi
  53. if [ "$check" == "200" ] ; then
  54. echo "online"
  55. if [ "$serverchan_notify_1" = "1" ] ; then
  56.     local hostIP=$(arIpAddress)
  57.     local lastIP=$(lastIPAddress)
  58.     if [ "$lastIP" != "$hostIP" ] && [ ! -z "$hostIP" ] ; then
  59.     sleep 60
  60.         local hostIP=$(arIpAddress)
  61.         local lastIP=$(lastIPAddress)
  62.     fi
  63.     if [ "$lastIP" != "$hostIP" ] && [ ! -z "$hostIP" ] ; then
  64.         logger -t "【互联网 IP 变动】" "目前 IP: ${hostIP}"
  65.         logger -t "【互联网 IP 变动】" "上次 IP: ${lastIP}"
  66.         curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】互联网IP变动" -d "&desp=${hostIP}" &
  67.         logger -t "【微信推送】" "互联网IP变动:${hostIP}"
  68.         echo -n $hostIP > /etc/storage/lastIPAddress
  69.     fi
  70. fi
  71. if [ "$serverchan_notify_2" = "1" ] ; then
  72.     # 获取接入设备名称
  73.     touch /tmp/var/newhostname.txt
  74.     echo "接入设备名称" > /tmp/var/newhostname.txt
  75.     #cat /tmp/syslog.log | grep 'Found new hostname' | awk '{print $7" "$8}' >> /tmp/var/newhostname.txt
  76.     cat /tmp/static_ip.inf | grep -v "^$" | awk -F "," '{ if ( $6 == 0 ) print "【内网IP:"$1",MAC:"$2",名称:"$3"】  "}' >> /tmp/var/newhostname.txt
  77.     # 读取以往接入设备名称
  78.     touch /etc/storage/hostname.txt
  79.     [ ! -s /etc/storage/hostname.txt ] && echo "接入设备名称" > /etc/storage/hostname.txt
  80.     # 获取新接入设备名称
  81.     awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行.txt
  82.     awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复.txt
  83.     if [ -s "/tmp/var/newhostname不重复.txt" ] ; then
  84.         content=`cat /tmp/var/newhostname不重复.txt | grep -v "^$"`
  85.         curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】新设备加入" -d "&desp=${content}" &
  86.         logger -t "【微信推送】" "PDCN新设备加入:${content}"
  87.         cat /tmp/var/newhostname不重复.txt | grep -v "^$" >> /etc/storage/hostname.txt
  88.     fi
  89. fi
  90. if [ "$serverchan_notify_4" = "1" ] ; then
  91.     # 设备上、下线提醒
  92.     # 获取接入设备名称
  93.     touch /tmp/var/newhostname.txt
  94.     echo "接入设备名称" > /tmp/var/newhostname.txt
  95.     #cat /tmp/syslog.log | grep 'Found new hostname' | awk '{print $7" "$8}' >> /tmp/var/newhostname.txt
  96.     cat /tmp/static_ip.inf | grep -v "^$" | awk -F "," '{ if ( $6 == 0 ) print "【内网IP:"$1",MAC:"$2",名称:"$3"】  "}' >> /tmp/var/newhostname.txt
  97.     # 读取以往上线设备名称
  98.     touch /etc/storage/hostname_上线.txt
  99.     [ ! -s /etc/storage/hostname_上线.txt ] && echo "接入设备名称" > /etc/storage/hostname_上线.txt
  100.     # 上线
  101.     awk 'NR==FNR{a[$0]++} NR>FNR&&a[$0]' /etc/storage/hostname_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname相同行_上线.txt
  102.     awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname相同行_上线.txt /tmp/var/newhostname.txt > /tmp/var/newhostname不重复_上线.txt
  103.     if [ -s "/tmp/var/newhostname不重复_上线.txt" ] ; then
  104.         content=`cat /tmp/var/newhostname不重复_上线.txt | grep -v "^$"`
  105.         curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】设备【上线】Online" -d "&desp=${content}" &
  106.         logger -t "【微信推送】" "PDCN设备【上线】:${content}"
  107.         cat /tmp/var/newhostname不重复_上线.txt | grep -v "^$" >> /etc/storage/hostname_上线.txt
  108.     fi
  109.     # 下线
  110.     awk 'NR==FNR{a[$0]++} NR>FNR&&!a[$0]' /tmp/var/newhostname.txt /etc/storage/hostname_上线.txt > /tmp/var/newhostname不重复_下线.txt
  111.     if [ -s "/tmp/var/newhostname不重复_下线.txt" ] ; then
  112.             if [ $count -lt 10 ];then  
  113.             let count++
  114.         else
  115.             CURTIMEout=$(date "+【%m-%d %H:%M:%S】")
  116.             content=`cat /tmp/var/newhostname不重复_下线.txt | grep -v "^$"`
  117.             curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】设备【下线】offline" -d "&desp=${content}  $CURTIMEout" &
  118.             logger -t "【微信推送】" "PDCN设备【下线】:${content}"
  119.             cat /tmp/var/newhostname.txt | grep -v "^$" > /etc/storage/hostname_上线.txt
  120.             count=0
  121.         fi
  122.     else
  123.         count=0

  124.     fi
  125. fi
  126. if [ "$serverchan_notify_3" = "1" ] && [ "$resub" = "1" ] ; then
  127.     # 固件更新提醒
  128.     [ ! -f /tmp/var/osub ] && echo -n `nvram get firmver_sub` > /tmp/var/osub
  129.     rm -f /tmp/var/nsub
  130.     wgetcurl.sh "/tmp/var/nsub" "$hiboyfile/osub" "$hiboyfile2/osub"
  131.     if [ $(cat /tmp/var/osub) != $(cat /tmp/var/nsub) ] && [ -f /tmp/var/nsub ] ; then
  132.         echo -n `nvram get firmver_sub` > /tmp/var/osub
  133.         content="新的固件: `cat /tmp/var/nsub | grep -v "^$"` ,目前旧固件: `cat /tmp/var/osub | grep -v "^$"` "
  134.         logger -t "【微信推送】" "固件 新的更新:${content}"
  135.         curl -s "http://sc.ftqq.com/$serverchan_sckey.send?text=【PDCN_"`nvram get computer_name`"】固件更新提醒" -d "&desp=${content}" &
  136.         echo -n `cat /tmp/var/nsub | grep -v "^$"` > /tmp/var/osub
  137.     fi
  138. fi
  139.     resub=`expr $resub + 1`
  140.     [ "$resub" -gt 360 ] && resub=1
  141. else
  142. echo "Internet down 互联网断线"
  143. resub=1
  144. fi
  145. sleep 60
  146. continue
  147. done
复制代码


评分

参与人数 1恩山币 +1 收起 理由
phrnet + 1 强大的恩山!(以下重复1万次)

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
发表于 2018-12-23 01:47 | 显示全部楼层
找了好久 竟然找到了 一直觉得这玩意太频繁了
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2018-12-23 01:48 | 显示全部楼层
我是直接改了最后的脚本休眠时间 让他睡3分钟才启动....

点评

这样把其它正常上线的的推送也延时了,原脚本设备上线是比较准时的。  详情 回复 发表于 2018-12-23 11:03
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2018-12-23 11:03 | 显示全部楼层
phrnet 发表于 2018-12-23 01:48
我是直接改了最后的脚本休眠时间 让他睡3分钟才启动....

这样把其它正常上线的的推送也延时了,原脚本设备上线是比较准时的。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-1-23 23:52 | 显示全部楼层
大大 ~
研究了半天 iPhone设备频繁上下线频繁推送有办法解决不?
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-1-25 18:54 | 显示全部楼层
我是感觉设备上下线不及时推送,怎么改?10改多少
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-4-19 21:41

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表