mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-29 16:05:13 +08:00
update 2026-09-26 17:00:06
This commit is contained in:
1 parent
97ae9f68da
commit
bcc9ceb04a
4756 files changed
+1670713
No files matched your search
@@ -0,0 +1,155 @@
|
||||
#!/bin/sh
|
||||
# author 2021 jjm2473
|
||||
# author 2020-2026 sirpdboy
|
||||
# Converted for OpenWrt 25.10
|
||||
|
||||
TMP_T=/var/taskplan/taskplan.tmp
|
||||
LOG=/etc/taskplan/taskplan.log
|
||||
|
||||
log(){
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S') $*" >> $LOG
|
||||
}
|
||||
|
||||
limit_log() {
|
||||
local logf=$1
|
||||
[ ! -f "$logf" ] && return
|
||||
local sc=100
|
||||
[ -n "$2" ] && sc=$2
|
||||
local count=$(grep -c "" $logf 2>/dev/null || echo 0)
|
||||
if [ $count -gt $sc ]; then
|
||||
let count=count-$sc
|
||||
sed -i "1,$count d" $logf 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
remwan3() {
|
||||
while true; do
|
||||
status=$(/usr/sbin/mwan3 status 2>/dev/null | grep -i error)
|
||||
if [ -z "$status" ]; then
|
||||
log "Mwan3 is OK"
|
||||
exit 0
|
||||
else
|
||||
log "mwan3 restarting ..."
|
||||
/usr/sbin/mwan3 restart
|
||||
fi
|
||||
sleep 60
|
||||
done
|
||||
}
|
||||
|
||||
disreconnwan() {
|
||||
i=0
|
||||
PingA=114.114.114.114
|
||||
PingB=223.5.5.5
|
||||
PingErr=1
|
||||
|
||||
while [ $i -lt 5 ]; do
|
||||
if ping -c 1 -W 3 $PingA >/dev/null 2>&1; then
|
||||
PingErr=0
|
||||
break
|
||||
elif ping -c 1 -W 3 $PingB >/dev/null 2>&1; then
|
||||
PingErr=0
|
||||
break
|
||||
else
|
||||
i=$((i + 1))
|
||||
sleep 10
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
trigger() {
|
||||
case "$1" in
|
||||
reboot)
|
||||
reboot
|
||||
;;
|
||||
poweroff)
|
||||
poweroff
|
||||
;;
|
||||
network)
|
||||
/etc/init.d/network restart
|
||||
;;
|
||||
clearmem)
|
||||
sync && echo 3 > /proc/sys/vm/drop_caches
|
||||
;;
|
||||
sysfree)
|
||||
cd /overlay
|
||||
rm -rf $(ls | egrep -v '(upper|.fs_state)') 2>/dev/null
|
||||
cd upper 2>/dev/null
|
||||
rm -rf $(ls | egrep -v '(etc)') 2>/dev/null
|
||||
cd etc 2>/dev/null
|
||||
rm -rf $(ls | egrep -v '(config|ssr|bench.log|shadow)') 2>/dev/null
|
||||
rm -rf /var/luci-modulecache 2>/dev/null
|
||||
rm -rf /var/luci-indexcache 2>/dev/null
|
||||
rm -rf /tmp/cache/* 2>/dev/null
|
||||
reboot
|
||||
;;
|
||||
restartsamba)
|
||||
/etc/init.d/ksmdb restart 2>/dev/null
|
||||
/etc/init.d/samba restart 2>/dev/null
|
||||
/etc/init.d/samba4 restart 2>/dev/null
|
||||
log "Samba restarted"
|
||||
;;
|
||||
restartlan)
|
||||
ifdown lan && ifup lan
|
||||
log "restart lan succeeded!"
|
||||
;;
|
||||
restartwan)
|
||||
ifup wan
|
||||
log "restart wan succeeded!"
|
||||
;;
|
||||
closewan)
|
||||
ifdown wan
|
||||
;;
|
||||
disreconn)
|
||||
disreconnwan
|
||||
if [ $PingErr = 1 ]; then
|
||||
ifup wan
|
||||
log "Redial succeeded!"
|
||||
fi
|
||||
;;
|
||||
disrereboot)
|
||||
disreconnwan
|
||||
if [ $PingErr = 1 ]; then
|
||||
log "Reboot succeeded!"
|
||||
reboot
|
||||
fi
|
||||
;;
|
||||
restartmwan3)
|
||||
[ -x /usr/sbin/mwan3 ] && remwan3
|
||||
;;
|
||||
customscript)
|
||||
if [ -s /etc/taskplan/taskplancustomscript ]; then
|
||||
bash /etc/taskplan/taskplancustomscript
|
||||
log "CustomScript succeeded!"
|
||||
else
|
||||
log "CustomScript run Error!"
|
||||
fi
|
||||
;;
|
||||
customscript2)
|
||||
if [ -s /etc/taskplan/taskplancustomscript2 ]; then
|
||||
bash /etc/taskplan/taskplancustomscript2
|
||||
log "CustomScript2 succeeded!"
|
||||
else
|
||||
log "CustomScript2 run Error!"
|
||||
fi
|
||||
;;
|
||||
upwifi)
|
||||
ifconfig wlan0 up 2>/dev/null
|
||||
uci set wireless.radio0.disabled=0 2>/dev/null
|
||||
uci set wireless.radio1.disabled=0 2>/dev/null
|
||||
uci commit wireless 2>/dev/null
|
||||
wifi up
|
||||
;;
|
||||
downwifi)
|
||||
ifconfig wlan0 down 2>/dev/null
|
||||
uci set wireless.radio0.disabled=1 2>/dev/null
|
||||
uci set wireless.radio1.disabled=1 2>/dev/null
|
||||
uci commit wireless 2>/dev/null
|
||||
wifi down
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
limit_log $LOG 500
|
||||
PingErr=0
|
||||
log "Scheduled operation $2: $1" && trigger $1
|
||||
|
||||
Reference in new issue
Block a user