Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wen-long/596d9818eb2037fc6efc to your computer and use it in GitHub Desktop.
Save wen-long/596d9818eb2037fc6efc to your computer and use it in GitHub Desktop.

E 信按需连接并发送通知给手机

exin_ontime.sh 如下

#! /bin/sh
export PATH="/bin:/usr/bin:/sbin:"$PATH
while true
do
    count=`cat /tmp/dhcp.leases | wc  -l`
    echo $count
    #有用户,尚未连接
    ifstat=`ifstatus NetKeeper |  grep  "up\": true," | wc -l`
    localtime=`date`
    if [ $count -ge 1 -a $ifstat -eq 0 ]
    then
        ifup NetKeeper
        sleep 2
        echo `date +"%m 月 %d 日 %T"`  "connect!" >>/root/exin_ontime.log
        curl -s -k --header 'Authorization: Bearer your_key_here' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "NetKeeper 已连接", "body": "当前时间是 '"$localtime"' "}' >> /root/ontime.log
        echo -e "\n\n"  >> /root/ontime.log

    #无用户,已连接
    elif [ $count -eq 0 -a $ifstat -eq 1 ]
    then
        curl -s -k --header 'Authorization: Bearer your_key_here' -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "NetKeeper 已关闭", "body": "当前时间是 '"$localtime"' "}' >> /root/ontime.log
        echo -e "\n\n"  >> /root/ontime.log
        sleep 2
        ifdown NetKeeper
        echo `date +"%m 月 %d 日 %T"`  "disconnect!" >> /root/exin_ontime.log
    fi
    sleep 6
done

rc.local 添加

/usr/bin/nohup /bin/sh /root/exin_ontime.sh &

DHCP 租期适当减小,如 5 min

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment