公司设备设置了映射,但是公网ip老是变化,于是利用serverchan写了一个bash脚本。
    脚本名称 pushIptowechat.sh

    1. #!/bin/bash
    2. ip=$(curl ip.sb)
    3. sckey="SCU********************************************************"
    4. pushurl="https://sc.ftqq.com/$sckey.send?desp=DeviceWanIp&text="
    5. curl ${pushurl}${ip}
    6. while :
    7. do
    8. sleep 10
    9. newip=$(curl ip.sb)
    10. if [ "$ip" = "$newip" ] ;then
    11. echo "ip is not changed.currentip is ${ip}"
    12. else
    13. echo "ip has changed,new ip is ${newip}"
    14. ip=${newip}
    15. curl ${pushurl}${ip}
    16. fi
    17. done

    sckey需要自己登陆微信去获取 Server Chan官网
    由于程序是一个死循环之类的,所以只需要开机启动即可。使用crontab -e来添加开机任务
    /bin/bash /home/root/pushIptowechat.sh >/dev/null 2>&1 &