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/m.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燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP