mud_sanc 板


LINE

今天忙死了。总之,新的工作室 day2,今天晚上看底下的东西 能不能 coding 完。 // _crontab.c // Laechan@Sanc add in 2018/01/08 // * * * * * 要做啥工作 格式大概长这样 // 目前已知有 a-b 及 */n 这两种 // n 若给错导致不能被整除的情况发生时就不会 match inherit DAEMON; mixed crontabs; void create() { ::create(); seteuid(getuid(this_object())); crontabs=({}); if(file_exists("/open/cmds/crontab.o")) restore_object("/open/cmds/crontab"); } int save_room() { save_object("/open/cmds/crontab"); return 1; } // 到以上为止的写法都很固定 // 暂时不开放 a,b,c * * * * 这种给法, 事实上它还能混合 // 例如 a,b,*/10 * * * * 这样会没完没了, 逗号先不开放 int illegel_check(string tmp,string kind,int min,int max) { int t,t1,t2; t=atoi(tmp); if(tmp=="*") return 0; else if(sscanf(min,"%d-%d",t1,t2)==2) { if(t1<min || t1>max || t2<min || t2>max || t1>=t2) { write("crontab -add: 你所给的"+kind+" '"+tmp+"' 格式不符喔.\n"); return 1; } return 0; } // 周不能有 / 号 else if(kind!="周" && sscanf(tmp,"*/%d",t1)==1) { // 要能整除 if(t1<min || t1>max || (t1!=0 && t%t1!=0)) { write("crontab -add: 你所给的"+kind+" '"+tmp+"' 格式不符喔.\n"); return 1; } return 0; } else if(sscanf(tmp,"%d",t)==1) { if(t<min || t>max) { write("crontab -add: 你所给的"+kind+" '"+tmp+"' 格式不符喔.\n"); return 1; } return 0; } write("crontab -add: 你所给的"+kind+" '"+tmp+"' 格式不符喔.\n"); return 1; } int cmd_crontab(string str,object me) { string what,files,funs,t1,t2,t3,t4,t5; int n,n1,n2; object ob; mixed tmps=({}); if(!str || str=="") return notify_fail(@LONG 例行排程(crontab)指令说明: ====================================================== crontab -list 例行排程列表 crontab -add xxx 将 xxx 加进排程中 crontab -del xxx 删掉 xxx 这个排程 每一个排程都是一行,前五个分别代表 分 时 日 月 周, 每一个都可以是 数字、a-b、或 a/b 或 * 的形式。再之後 所接的东西固定为 什麽物件->呼叫什麽函数 例子 * * * * * /d/event/control->newyear 每分钟的呼叫 0 * * * * /d/event/control->newyear 每小时整点呼叫 */10 * * * * /d/event/control->newyear 每10分钟的呼叫 ====================================================== LONG ); else if(str=="-l" || str=="-list") return notify_fail(implode(crontabs,"\n")+"\n"); else if(sscanf(str,"-add %s",what)==1) { if(sscanf(what,"%s %s %s %s %s %s->%s", t1,t2,t3,t4,t5,files,funs)!=7) return notify_fail("格式: 分 时 日 月 周 物件档->函数名\n"+ " 前五个可给 数字,a-b,a/b 及 * 等.\n"); // 不能有完全一模一样的 if(member_array(what,crontabs)!=-1) return notify_fail("crontab -add: 这条例行排程已经有了喔!\n"); if(illegel_check(t1,"分",0,59)>0) return notify_fail(""); if(illegel_check(t2,"时",0,23)>0) return notify_fail(""); if(illegel_check(t3,"日",1,31)>0) return notify_fail(""); if(illegel_check(t4,"月",1,12)>0) return notify_fail(""); // 周不能用 / 号 if(illegel_check(t5,"周",1,7)>0) return notify_fail(""); // 通过上面的判断就可以加进去 crontabs+=({what}); save_room(); return notify_fail("crontab -add: 这个例行排程已加入.\n"); } else if(sscanf(str,"-del %s",what)==1 || sscanf(str,"-delete %s",what)==1) { if(member_array(what,crontabs)==-1) return notify_fail("crontab -del: 没有这个例行排程喔.\n"); crontabs-=({what}); save_room(); return notify_fail("crontab -del: 这个例行排程已删除.\n"); } return notify_fail("没有 crontab "+str+" 这个语法喔.\n"); } 大概是上面的感觉吧,明天再放到 sanc 跑看看。 Laechan --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 122.117.106.224
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/mud_sanc/M.1515419449.A.7CC.html 写一下在 times_check 内的判断好了 总之要从 ctime 里面抽出 min hour day mon week int s; mixed times=({0,0,0,0,0}); times=({min,hour,day,mon,week}); foreach(c in crontabs) { sscanf(c,"%s %s %s %s %s %s->%s",c1,c2,c3,c4,c5,c6,c7); tmps=({c1,c2,c3,c4,c5}); s=0; for(i=0;i<5;i++) { tmp=tmps[i]; if(tmp=="*") s++; else if(sscanf(tmp,"%d-%d",n1,n2)==2) { if(times[i]>=n1 && times[i]<=n2) s++; } else if(sscanf(tmp,"*/%d",n1)==1) { if(times[i]%n1==0) s++; } else if(sscanf(tmp,"%d",n1)==1) { if(times[i]==n1) s++; } } // 能执行到这里代表 s = 5, 那就做 files->funs 的动作 if(s==5) catch(call_other(c6,substr(c7,"()","")); } 上面都是变数内的整数及字串判断,就算每分钟执行一次,对系统 的负担也不大。
1F:→ laechan : 修正了一些写法 01/09 07:15
※ 编辑: laechan (122.117.106.224), 01/09/2018 07:48:39







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:iOS站内搜寻

TOP