适用于 Windows 的类似 Cron 的系统?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/638124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:08:18  来源:igfitidea点击:

Cron-like system for Windows?

windowscron

提问by mghaoui

I'm looking for an equivalent to a Cron system for Windows. The idea is to able to schedule a trigger and monitor whether it has run successfully or not.

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

What the system need to do is the following:

系统需要做的是:

  • It should be able to trigger Win32 COM objects and/or executables.
  • It should be able to trigger .NET COM objects and/or .NET executables.
  • It should be able to trigger scripts written in any language, either based on native framework (Python, Perl, Ruby) or based on the DLR (IronPython, Ruby.NET, whatever)
  • The scripts should range between simple scripts that take a few seconds to fairly heavy ones that can take up to half an hour.
  • 它应该能够触发 Win32 COM 对象和/或可执行文件。
  • 它应该能够触发 .NET COM 对象和/或 .NET 可执行文件。
  • 它应该能够触发以任何语言编写的脚本,无论是基于本机框架(Python、Perl、Ruby)还是基于 DLR(IronPython、Ruby.NET,等等)
  • 脚本的范围应介于需要几秒钟的简单脚本和可能需要长达半小时的相当繁重的脚本之间。

The monitoring aspect is critical. So basically I'm looking for the following:

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

  • If the script or executable fails then an e-mail should be sent or some other notification mechanism.
  • Every trigger should be logged so that we can look back and see when the code has failed.
  • The failure should easily be traced either through some sort of debug output or stack trace.
  • 如果脚本或可执行文件失败,则应发送电子邮件或其他通知机制。
  • 应该记录每个触发器,以便我们可以回顾并查看代码何时失败。
  • 应该可以通过某种调试输出或堆栈跟踪轻松跟踪故障。

Are there any Windows developers out there who have created such a system? I know in the UNIX world there is Cron but what about in the Windows world?

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

回答by vrdhn

At command prompt type 'at'

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

回答by Daniel

You should be able to use the scheduled task for all the above.

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

回答by boflynn

I would suggest looking at revised Task Scheduler 2.0 in Vista/Server 2008. It is much more powerful than 1.0 in previous versions of Windows, now able to

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

  • Event based triggers, e.g. every time an Application event code 1053 is caused
  • Triggers on failed tasks (the biggest addition for me)
  • More built in actions, such as sending emails instead of calling blat.exe
  • 基于事件的触发器,例如每次导致应用程序事件代码 1053 时
  • 触发失败的任务(对我来说最大的补充)
  • 更多内置操作,例如发送电子邮件而不是调用 blat.exe

Looking over your list, I believe that everything you are looking for is already there.

查看您的清单,我相信您要寻找的一切都已经存在。

回答by Davorin

Take a look at nnCron. I'm using a Lite version. It has a unix crontab syntax. There is a log file but as for more advanced monitoring aspects, it's up to your script/application to provide details, eg. return Result code (that will be logged).

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

nnCron Lite was the best cron clone for windows (free, no perl requirement, crontab, missed tasks, run as hidden window, set enviroment variable - useful for postgres "dump all" tool, etc.) that I found.

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

回答by Ken White

Have you looked at Windows Scheduler? It seems to meet most, if not all, of your requirements, and is already included in the OS. You can find it documented at MSDN

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

回答by Anthony

If you want a script to "trigger Win32 COM objects and/or executables", "trigger .NET COM objects and/or .NET executables", log failures and notify of failures by email, that sounds to me like a job for PowerShell.

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

PowerShell doesn't have logging and emailing done for you, rather it's a programming language where you can log or send email (or whatever) fairly easily.

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

I have scheduled PowerShell scripts to run using the "at" / "Task Scheduler" service, with success. It's a good combination.

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

回答by prinzdezibel

Have you tried JIT-Scheduler in combination with PowerShell?

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

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

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

回答by schnaader

Have a look here: Cron for Windows. There also was some Cron-like software ported for (Free)DOS that should work on Windows, but I can't remember the name.

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