【问题标题】:Cron-like system for Windows?类似 Cron 的 Windows 系统?
【发布时间】:2009-03-12 11:00:23
【问题描述】:

我正在寻找一个等效于 Windows 的 Cron 系统。这个想法是能够安排一个触发器并监控它是否成功运行。

系统需要做的事情如下:

  • 它应该能够触发 Win32 COM 对象和/或可执行文件。
  • 它应该能够触发 .NET COM 对象和/或 .NET 可执行文件。
  • 它应该能够触发以任何语言编写的脚本,无论是基于原生框架(Python、Perl、Ruby)还是基于 DLR(IronPython、Ruby.NET 等)
  • 脚本应介于需要几秒钟的简单脚本和可能需要半小时的相当繁重的脚本之间。

监控方面至关重要。所以基本上我正在寻找以下内容:

  • 如果脚本或可执行文件失败,则应发送电子邮件或其他通知机制。
  • 应记录每个触发器,以便我们回顾代码何时失败。
  • 应该通过某种调试输出或堆栈跟踪轻松跟踪故障。

是否有任何 Windows 开发人员创建了这样的系统?我知道在 UNIX 世界中有 Cron,但在 Windows 世界中呢?

【问题讨论】:

    标签: windows cron


    【解决方案1】:

    在命令提示符下输入'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.
    

    【讨论】:

      【解决方案2】:

      您应该能够将计划任务用于上述所有操作。

      【讨论】:

      • 这个答案如何调用 COM/.NET 对象(不是可执行文件)? OP 要求的监控如何?
      • 由于可以调用 vb 脚本(可以调用 com)和 bat 文件,因此完全可以通过调度程序调用 com 对象。至于监控,它可能必须嵌入到被调用的脚本中。
      【解决方案3】:

      我建议查看修改后的Task Scheduler 2.0 in Vista/Server 2008。它比以前版本的 Windows 1.0 强大得多,现在可以

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

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

      【讨论】:

        【解决方案4】:

        您看过 Windows 调度程序吗?它似乎满足了您的大部分(如果不是全部)要求,并且已经包含在操作系统中。你可以在MSDN找到它的文档

        【讨论】:

          【解决方案5】:

          如果你想要一个脚本来“触发 Win32 COM 对象和/或可执行文件”、“触发 .NET COM 对象和/或 .NET 可执行文件”、记录失败并通过电子邮件通知失败,这听起来像是一份工作为PowerShell

          PowerShell 没有为您完成记录和发送电子邮件,而是一种编程语言,您可以在其中相当轻松地记录或发送电子邮件(或其他)。

          我已成功安排 PowerShell 脚本使用“at”/“Task Scheduler”服务运行。这是一个很好的组合。

          【讨论】:

            【解决方案6】:

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

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

            【讨论】:

              【解决方案7】:

              请看这里:Cron for Windows。还有一些为(免费)DOS 移植的类似 Cron 的软件,应该可以在 Windows 上运行,但我不记得名字了。

              【讨论】:

                【解决方案8】:

                您是否尝试过将 JIT-Scheduler 与 PowerShell 结合使用?

                http://shareme.com/download/jit-scheduler.html

                【讨论】:

                  猜你喜欢
                  • 2013-05-08
                  • 2010-11-04
                  • 2011-12-03
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2013-01-22
                  相关资源
                  最近更新 更多