mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 04:25:13 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,33 @@
|
||||
|
||||
config global
|
||||
option enabled '0'
|
||||
option customscript '# Sh script rules'
|
||||
option customscript2 '# Sh script rules'
|
||||
|
||||
config stime
|
||||
option week '*'
|
||||
option stype '2'
|
||||
option month '*'
|
||||
option enable '0'
|
||||
option ttype '0'
|
||||
option delay '10'
|
||||
option remarks '每天22:30执行'
|
||||
option hour '22'
|
||||
option minute '30'
|
||||
config stime
|
||||
option week '*'
|
||||
option month '*'
|
||||
option stype '11'
|
||||
option ttype '1'
|
||||
option delay '20'
|
||||
option enable '0'
|
||||
option hour '*'
|
||||
option remarks '每月每天每过4分钟执行'
|
||||
option minute '*/4'
|
||||
|
||||
config ltime
|
||||
option remarks '开机启动延时30秒执行'
|
||||
option stype '11'
|
||||
option delay '30'
|
||||
option enable '0'
|
||||
|
||||
Executable
+143
@@ -0,0 +1,143 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# copyright by sirpdboy
|
||||
# Converted for OpenWrt 25.10
|
||||
|
||||
START=99
|
||||
STOP=10
|
||||
TMP=/etc/taskplan
|
||||
LOG=$TMP/taskplan.log
|
||||
TT=/etc/taskplan/taskplanrun
|
||||
CR=/etc/crontabs/root
|
||||
|
||||
# 确保目录存在
|
||||
[ ! -d $TMP ] && mkdir -p $TMP 2>/dev/null
|
||||
[ ! -s $LOG ] && echo '' > $LOG
|
||||
|
||||
run_taskplan()
|
||||
{
|
||||
[ -n "$(uci -q get taskplan.@global[0].customscript)" ] && \
|
||||
uci -q get taskplan.@global[0].customscript > /etc/taskplan/taskplancustomscript && \
|
||||
sed -i 's/\r$//' /etc/taskplan/taskplancustomscript
|
||||
|
||||
[ -n "$(uci -q get taskplan.@global[0].customscript2)" ] && \
|
||||
uci -q get taskplan.@global[0].customscript2 > /etc/taskplan/taskplancustomscript2 && \
|
||||
sed -i 's/\r$//' /etc/taskplan/taskplancustomscript2
|
||||
|
||||
ssum=$(uci -q show taskplan | grep -c "stime\[[0-9]\]" || echo 0)
|
||||
lsum=$(uci -q show taskplan | grep -c "ltime\[[0-9]\]" || echo 0)
|
||||
|
||||
# 清空crontab中的taskplan条目
|
||||
sed -i '/taskplanhandler/d' $CR >/dev/null 2>&1
|
||||
|
||||
# 处理定时任务
|
||||
for i in $(seq 0 $((ssum-1)) 2>/dev/null); do
|
||||
enable=$(uci -q get taskplan.@stime[$i].enable)
|
||||
if [ "x$enable" = "x1" ]; then
|
||||
month=$(uci -q get taskplan.@stime[$i].month || echo "*")
|
||||
stype=$(uci -q get taskplan.@stime[$i].stype)
|
||||
week=$(uci -q get taskplan.@stime[$i].week || echo "*")
|
||||
minute=$(uci -q get taskplan.@stime[$i].minute || echo "0")
|
||||
hour=$(uci -q get taskplan.@stime[$i].hour || echo "*")
|
||||
|
||||
# 格式化时间
|
||||
[ "$hour" = "0" ] && hour="0"
|
||||
[ "$minute" = "0" ] && minute="0"
|
||||
|
||||
case "$stype" in
|
||||
1) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler reboot Scheduled_task" ;;
|
||||
2) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler poweroff Scheduled_task" ;;
|
||||
3) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler network Scheduled_task" ;;
|
||||
4) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartsamba Scheduled_task" ;;
|
||||
5) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartwan Scheduled_task" ;;
|
||||
6) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler closewan Scheduled_task" ;;
|
||||
7) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler clearmem Scheduled_task" ;;
|
||||
8) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler sysfree Scheduled_task" ;;
|
||||
9) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler disreconn Scheduled_task" ;;
|
||||
10) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler disrereboot Scheduled_task" ;;
|
||||
11) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartmwan3 Scheduled_task" ;;
|
||||
12) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler customscript Scheduled_task" ;;
|
||||
13) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler upwifi Scheduled_task" ;;
|
||||
14) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler downwifi Scheduled_task" ;;
|
||||
15) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler customscript2 Scheduled_task" ;;
|
||||
16) cmd="$minute $hour * $month $week /usr/bin/taskplanhandler restartlan Scheduled_task" ;;
|
||||
esac
|
||||
echo "$cmd" >> $CR
|
||||
fi
|
||||
done
|
||||
|
||||
# 创建启动任务脚本
|
||||
echo "#!/bin/sh" > $TT
|
||||
chmod +x $TT
|
||||
|
||||
for i in $(seq 0 $((lsum-1)) 2>/dev/null); do
|
||||
enable=$(uci -q get taskplan.@ltime[$i].enable)
|
||||
if [ "x$enable" = "x1" ]; then
|
||||
stype=$(uci -q get taskplan.@ltime[$i].stype)
|
||||
delay=$(uci -q get taskplan.@ltime[$i].delay || echo 10)
|
||||
|
||||
case "$stype" in
|
||||
1) echo "(sleep $delay && /usr/bin/taskplanhandler reboot Startup_task) &" >>$TT ;;
|
||||
2) echo "(sleep $delay && /usr/bin/taskplanhandler poweroff Startup_task) &" >>$TT ;;
|
||||
3) echo "(sleep $delay && /usr/bin/taskplanhandler network Startup_task) &" >>$TT ;;
|
||||
4) echo "(sleep $delay && /usr/bin/taskplanhandler restartsamba Startup_task) &" >>$TT ;;
|
||||
5) echo "(sleep $delay && /usr/bin/taskplanhandler restartwan Startup_task) &" >>$TT ;;
|
||||
6) echo "(sleep $delay && /usr/bin/taskplanhandler closewan Startup_task) &" >>$TT ;;
|
||||
7) echo "(sleep $delay && /usr/bin/taskplanhandler clearmem Startup_task) &" >>$TT ;;
|
||||
8) echo "(sleep $delay && /usr/bin/taskplanhandler sysfree Startup_task) &" >>$TT ;;
|
||||
9) echo "(sleep $delay && /usr/bin/taskplanhandler disreconn Startup_task) &" >>$TT ;;
|
||||
10) echo "(sleep $delay && /usr/bin/taskplanhandler disrereboot Startup_task) &" >>$TT ;;
|
||||
11) echo "(sleep $delay && /usr/bin/taskplanhandler restartmwan3 Startup_task) &" >>$TT ;;
|
||||
12) echo "(sleep $delay && /usr/bin/taskplanhandler customscript Startup_task) &" >>$TT ;;
|
||||
13) echo "(sleep $delay && /usr/bin/taskplanhandler upwifi Startup_task) &" >>$TT ;;
|
||||
14) echo "(sleep $delay && /usr/bin/taskplanhandler downwifi Startup_task) &" >>$TT ;;
|
||||
15) echo "(sleep $delay && /usr/bin/taskplanhandler customscript2 Startup_task) &" >>$TT ;;
|
||||
16) echo "(sleep $delay && /usr/bin/taskplanhandler restartlan Startup_task) &" >>$TT ;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
echo 'wait' >> $TT
|
||||
echo 'exit 0' >> $TT
|
||||
}
|
||||
|
||||
start()
|
||||
{
|
||||
del_cru
|
||||
run_taskplan
|
||||
/etc/init.d/cron reload
|
||||
echo "$(date): taskplan started" >> $LOG
|
||||
}
|
||||
|
||||
boot()
|
||||
{
|
||||
# 启动时执行
|
||||
del_cru
|
||||
run_taskplan
|
||||
/etc/init.d/cron reload
|
||||
|
||||
if [ -f $TT ] && [ -s $TT ]; then
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S'): Executing taskplanrun at boot" >> $LOG
|
||||
bash $TT >> $LOG 2>&1 &
|
||||
else
|
||||
echo "$(date +'%Y-%m-%d %H:%M:%S'): taskplanrun file not found or empty at boot" >> $LOG
|
||||
fi
|
||||
}
|
||||
|
||||
stop()
|
||||
{
|
||||
del_cru
|
||||
/etc/init.d/cron reload
|
||||
}
|
||||
|
||||
restart()
|
||||
{
|
||||
stop
|
||||
sleep 2
|
||||
start
|
||||
}
|
||||
del_cru()
|
||||
{
|
||||
sed -i '/taskplanhandler/d' $CR >/dev/null 2>&1 || true
|
||||
echo "#!/bin/sh" > $TT # 清空文件但保留基本结构
|
||||
chmod +x $TT
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash\n# Add your commands here
|
||||
@@ -0,0 +1 @@
|
||||
#!/bin/bash\n# Add your commands here
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo ""
|
||||
exit 0
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
if [ ! -f /etc/config/taskplan ]; then
|
||||
cat > /etc/config/taskplan << EOF
|
||||
config global 'global'
|
||||
option customscript ' '
|
||||
option customscript2 ' '
|
||||
|
||||
EOF
|
||||
fi
|
||||
mkdir -p /etc/taskplan
|
||||
touch /etc/taskplan/taskplan.log
|
||||
chmod +x /usr/libexec/rpcd/luci.taskplan /etc/init.d/taskplan /etc/taskplan/taskplanrun /usr/bin/taskplanhandler
|
||||
rm -rf /tmp/luci-modulecache /tmp/luci-indexcache*
|
||||
|
||||
exit 0
|
||||
Reference in new issue
Block a user