楼主: 
laechan (挥泪斩马云)   
2018-01-08 21:50:46今天忙死了。总之,新的工作室 day2,今天晚上看底下的东西
能不能 coding 完。
// _crontab.c
// [email protected] 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