~定时任务增加条件“运行时每分钟执行”
~修复定时任务中部分推荐任务无法添加的bug
~修复定时任务因找不到目录执行失败的bug
~修复修改定时任务时原任务被意外删除的bug
This commit is contained in:
juewuy
2024-01-03 10:31:32 +08:00
parent 732111b87a
commit 343e883070
8 changed files with 51 additions and 25 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -3,4 +3,4 @@ clashpre_v=2022.11.25
clash_v=v1.7.1
meta_v=v1.17.0
GeoIP_v=20231230
versionsh=1.8.2f
versionsh=1.8.2g

View File

@@ -1,16 +1,16 @@
#任务ID#任务命令#任务说明(#号隔开,任务命令和说明中都不允许包含#号)
101#$clashdir/start.sh start#启动clash服务
102#$clashdir/start.sh stop#停止clash服务
103#$clashdir/start.sh restart#重启clash服务
104#$clashdir/start.sh getyaml && $clashdir/start.sh restart#更新订阅并重启服务
105#$clashdir/start.sh updateyaml#热更新订阅
106#$clashdir/start.sh web_save#自动保存面板配置
107#$clashdir/start.sh ntp#自动同步ntp时间
101#$CRASHDIR/start.sh start#启动clash服务
102#$CRASHDIR/start.sh stop#停止clash服务
103#$CRASHDIR/start.sh restart#重启clash服务
104#$CRASHDIR/start.sh getyaml && $CRASHDIR/start.sh restart#更新订阅并重启服务
105#$CRASHDIR/start.sh updateyaml#热更新订阅
106#$CRASHDIR/start.sh web_save#自动保存面板配置
107#$CRASHDIR/start.sh ntp#自动同步ntp时间
111#$clashdir/task/task.sh update_core#自动更新内核
112#$clashdir/task/task.sh update_shellclash#自动更新脚本
113#$clashdir/task/task.sh update_mmdb#自动更新数据库文件
111#$CRASHDIR/task/task.sh update_core#自动更新内核
112#$CRASHDIR/task/task.sh update_shellclash#自动更新脚本
113#$CRASHDIR/task/task.sh update_mmdb#自动更新数据库文件
121#$clashdir/task/task.sh reset_firewall#重设透明路由防火墙
121#$CRASHDIR/task/task.sh reset_firewall#重设透明路由防火墙

View File

@@ -1,7 +1,7 @@
#!/bin/sh
# Copyright (C) Juewuy
version=1.8.2f
version=1.8.2g
setdir(){
dir_avail(){

View File

@@ -1298,6 +1298,12 @@ afstart(){
{ sleep 5;logger Clash服务已启动;} & #推送日志
#执行条件任务
[ -s $CRASHDIR/task/afstart ] && { source $CRASHDIR/task/afstart ;} &
[ -s $CRASHDIR/task/running ] && {
cronset '运行时每'
while read line ;do
cronset '2fjdi124dd12s' "$line"
done < $CRASHDIR/task/running
}
[ -s $CRASHDIR/task/affirewall -a -s /etc/init.d/firewall -a ! -f /etc/init.d/firewall.bak ] && {
#注入防火墙
line=$(grep -En "fw3 restart" /etc/init.d/firewall | cut -d ":" -f 1)
@@ -1354,9 +1360,9 @@ stop)
logger Clash服务即将关闭……
[ -n "$(pidof clash)" ] && web_save #保存面板配置
#删除守护进程&面板配置自动保存
cronset "clash保守模式守护进程"
cronset "保存面板配置"
cronset "流媒体预解析"
cronset '保守模式守护进程'
cronset '运行时每'
cronset '流媒体预解析'
#多种方式结束进程
if [ -f /etc/rc.common ];then
/etc/init.d/clash stop >/dev/null 2>&1
@@ -1465,7 +1471,7 @@ web_restore)
;;
daemon)
getconfig
cronset '#clash保守模式守护进程' "*/1 * * * * test -z \"\$(pidof clash)\" && $CRASHDIR/start.sh restart #clash保守模式守护进程"
cronset '保守模式守护进程' "*/1 * * * * test -z \"\$(pidof clash)\" && $CRASHDIR/start.sh restart #保守模式守护进程"
;;
cronset)
cronset $2 $3

View File

@@ -147,7 +147,6 @@ cronset(){
rm -f $tmpcron
#华硕/Padavan固件存档在本地,其他则删除
[ "$CRASHDIR" = "/jffs/clash" -o "$CRASHDIR" = "/etc/storage/clash" ] && mv -f $tmpcron $CRASHDIR/task/cron || rm -f $tmpcron
echo -e "任务:【$1】\033[32m添加成功\033[0m"
}
set_cron(){
[ -z $week ] && week=*
@@ -161,13 +160,20 @@ set_cron(){
cronset "$cron_time$task_name" "$task_txt"
fi
unset week hour min
echo -e "任务:【$cron_time$task_name】\033[32m添加成功\033[0m"
sleep 1
}
set_service(){
# 参数1代表要任务类型,参数2代表任务ID参数3代表任务描述
# 参数1代表要任务类型,参数2代表任务ID,参数3代表任务描述,参数4代表running任务运行间隔
task_file=$CRASHDIR/task/$1
[ -s $task_file ] && sed -i "/$3/d" $task_file
echo "$CRASHDIR/task/task.sh $2 $3" >> $task_file
if [ "$1" = "running" ];then
task_txt="$4 * * * * $CRASHDIR/task/task.sh $2 $3"
echo "$task_txt" >> $task_file #运行时每分钟执行的任务特殊处理
[ -n "$(pidof clash)" ] && cronset "$3" "$task_txt"
else
echo "$CRASHDIR/task/task.sh $2 $3" >> $task_file
fi
echo -e "任务:【$3】\033[32m添加成功\033[0m"
sleep 1
}
@@ -248,6 +254,7 @@ task_del(){ #任务删除
#删除条件任务
sed -i "/$1/d" $CRASHDIR/task/bfstart 2>/dev/null
sed -i "/$1/d" $CRASHDIR/task/afstart 2>/dev/null
sed -i "/$1/d" $CRASHDIR/task/running 2>/dev/null
sed -i "/$1/d" $CRASHDIR/task/affirewall 2>/dev/null
}
task_type(){ #任务条件选择菜单
@@ -260,13 +267,15 @@ task_type(){ #任务条件选择菜单
echo -e " 4 定时任务\033[32m每分钟执行\033[0m"
echo -e " 5 服务\033[33m启动前执行\033[0m"
echo -e " 6 服务\033[33m启动后执行\033[0m"
echo -e " 7 防火墙服务\033[33m重启后执行\033[0m"
echo -e " 7 服务\033[33m运行时每分钟执行\033[0m"
echo -e " 8 防火墙服务\033[33m重启后执行\033[0m"
echo -----------------------------------------------
echo -e " 0 返回上级菜单"
read -p "请输入对应数字 > " num
case "$num" in
0)
return 1
;;
1)
echo -----------------------------------------------
@@ -310,20 +319,30 @@ task_type(){ #任务条件选择菜单
set_service afstart "$task_id" "服务启动后$task_name"
;;
7)
echo -----------------------------------------------
echo -e " 输入10即每隔10分钟运行一次1440即每隔24小时运行一次"
read -p "想每隔多少分钟执行一次?(整数) > " num
min="*/$num"
set_service running "$task_id" "运行时每$num分钟$task_name" "$min"
;;
8)
echo -e "该功能会将相关启动代码注入到/etc/init.d/firewall中"
read -p "是否继续?(1/0) > " res
[ "$res" = 1 ] && set_service affirewall "$task_id" "防火墙重启后$task_name"
;;
*)
errornum
return 1
;;
esac
}
task_manager(){ #任务管理列表
echo -----------------------------------------------
#抽取并生成临时列表
croncmd -l | grep -oE "$CRASHDIR/task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > $TMPDIR/task_list
croncmd -l > $TMPDIR/task_cronlist
cat $TMPDIR/task_cronlist $CRASHDIR/task/running | sort -u | grep -oE "task/task.sh .*" | awk -F ' ' '{print $2" "$3}' > $TMPDIR/task_list
cat $CRASHDIR/task/bfstart $CRASHDIR/task/afstart $CRASHDIR/task/affirewall 2>/dev/null | awk -F ' ' '{print $2" "$3}' >> $TMPDIR/task_list
rm -rf $TMPDIR/task_cronlist
#判断为空则返回
if [ ! -s $TMPDIR/task_list ];then
echo -e "\033[31m当前没有可供管理的任务\033[36m"
@@ -406,9 +425,10 @@ task_recom(){ #任务推荐
echo -----------------------------------------------
read -p "是否启用?(1/0) > " res
[ "$res" = 1 ] && {
cronset "每隔10分钟自动保存面板配置" "*/10 * * * * $CRASHDIR/task/task.sh 106 每隔10分钟自动保存面板配置"
cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 /data/clash/task/task.sh 104 在每周3的3点整更新订阅并重启服务"
set_service afstart "107" "服务启动后自动同步ntp时间"
set_service running "106" "运行时每10分钟自动保存面板配置" "1/10"
set_service afstart "107" "服务启动后自动同步ntp时间"
cronset "在每周3的3点整更新订阅并重启服务" "0 3 * * 3 $CRASHDIR/task/task.sh 104 在每周3的3点整更新订阅并重启服务" && \
echo -e "任务:【在每周3的3点整更新订阅并重启服务】\033[32m添加成功\033[0m"
}
}
task_menu(){ #任务菜单