类似Cron的Windows系统?

4
我正在寻找Windows系统的Cron系统等效替代品。其想法是能够安排触发器并监视它是否成功运行。
系统需要执行以下操作:
- 它应该能够触发Win32 COM对象和/或可执行文件。 - 它应该能够触发.NET COM对象和/或.NET可执行文件。 - 它应该能够触发用任何语言编写的脚本,无论是基于本机框架(Python、Perl、Ruby)还是基于DLR(IronPython、Ruby.NET等)。 - 脚本范围从需要几秒钟到可能需要半个小时的重型脚本不等。
监控方面非常关键。因此,我正在寻找以下内容:
- 如果脚本或可执行文件失败,则应发送电子邮件或其他通知机制。 - 每个触发器都应记录下来,以便我们可以回顾代码何时失败。 - 失败应通过某种调试输出或堆栈跟踪轻松追踪。
有没有创建这样一个系统的Windows开发人员?我知道在UNIX世界中有Cron,但在Windows世界中呢?
8个回答

7

在命令提示符处键入“ at ”。

> at /?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.

6
您应该能够使用预定任务来完成上述所有操作。

这个答案如何调用COM/.NET对象(而不是可执行文件)?这个答案如何具有OP所要求的监视功能? - Aardvark
由于可以调用VB脚本(可以调用COM)和批处理文件,因此完全可以通过计划程序调用COM对象。至于监视,可能需要嵌入到被调用的脚本中。 - Daniel

3
我建议您查看修订后的Vista/Server 2008中的任务计划程序2.0。 它比以前版本的Windows中的1.0功能更强大,现在能够:

  • 基于事件的触发器,例如每次引发应用程序事件代码1053时
  • 失败任务的触发器(对我来说是最大的补充)
  • 更多内置操作,例如发送电子邮件而不是调用blat.exe

查看您的列表,我相信您需要的所有内容都已经存在。


1

你有没有看过Windows Scheduler?它似乎满足了你的大部分,如果不是全部,需求,并且已经包含在操作系统中。你可以在MSDN上找到相关文档。


1
如果你想要一个脚本来“触发Win32 COM对象和/或可执行文件”,“触发.NET COM对象和/或.NET可执行文件”,记录失败并通过电子邮件通知失败,那对我来说听起来像是 PowerShell 的工作。
PowerShell并没有为您完成日志记录和电子邮件功能,相反它是一种编程语言,您可以很容易地记录或发送电子邮件(或其他操作)。
我已经使用“at”/“任务计划程序”服务成功地安排了PowerShell脚本的运行。这是一个很好的组合。

1

看一下nnCron。我正在使用Lite版本。它具有Unix crontab语法。有一个日志文件,但对于更高级的监控方面,需要您的脚本/应用程序提供详细信息,例如返回结果代码(将被记录在日志中)。

我发现nnCron Lite是Windows上最好的cron克隆(免费,无需perl,crontab,错过任务,作为隐藏窗口运行,设置环境变量-对于postgres“dump all”工具非常有用等)。


0

请看这里:Windows下的Cron。还有一些类似Cron的软件被移植到了(Free)DOS上,应该也可以在Windows上运行,但我记不得它的名字了。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接