由于天翼网关不支持定时重启,另外app里设置定时重启也没有作用,
所以查找了一些相关工具和用法,再结合前辈的经验:参考的博客网址,自己最终把该功能实现了。
首先需要用winscp登陆到刷了openwrt的路由器中,
然后在/usr/bin/ 目录下建立一个reboot.sh文件,文件内容如下,其中的网址中的IP请改为天翼网关的IP地址,
另外“用户名”、“密码”也改为相应的登陆名和密码。
#!/bin/sh
loginfo=$(curl -s -L http://192.168.1.100/cgi-bin/luci -X POST -c cookies.txt -d 'username=用户名&psd=密码')
function mygetip()
{
ipinfo=$(curl -s -b cookies.txt http://192.168.1.100/cgi-bin/luci/admin/settings/gwinfo?get=all)
WanIp=$(echo $ipinfo | sed 's/,/\n/g' | grep -w WANIP)
echo WANIP information —— $WanIp
}
function myrestart()
{
mytoken=$(echo $loginfo |sed 's/{/\n/g' | grep token |awk '/realRestart/{print $2}' |sed $'s/\'//g')
mytoken='token='$mytoken
curl -s -b cookies.txt http://192.168.1.100/cgi-bin/luci/admin/reboot --data $mytoken
if [ $? -ne 0 ]; then
echo $mytoken reboot failed
else
echo $mytoken rebooting!
fi
}
#mygetip
myrestart
之后就将这个sh文件添加到计划任务执行就可以。