在 Windows 中设置 cron 作业

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7195503/
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-09 08:43:18  来源:igfitidea点击:

Setting up a cron job in Windows

windowscronscheduled-tasks

提问by mona

I have to download a file from an SFTP server everyday. I have the program which retrieves the file from the server but I was thinking of setting up a cron job (or anything similar) to automate that. We are a Windows shop and need to set up the cron job in Windows.

我必须每天从 SFTP 服务器下载文件。我有从服务器检索文件的程序,但我正在考虑设置一个 cron 作业(或任何类似的东西)来自动化它。我们是一家 Windows 商店,需要在 Windows 中设置 cron 作业。

回答by steenhulthin

The windows equivalent to a cron job is a scheduled task.

相当于 cron 作业的窗口是计划任务。

A scheduled task can be created as described by Alexand Rudu, but it can also be done command line with schtasks(if you for instance need to script it or add it to version control).

可以按照AlexRudu 的描述创建计划任务,但也可以使用命令行完成schtasks(例如,如果您需要编写脚本或将其添加到版本控制中)。

An example:

一个例子:

schtasks /create /tn calculate /tr calc /sc weekly /d MON /st 06:05 /ru "System"

Creates the task calculate, which starts the calculator(calc) every monday at 6:05 (should you ever need that.)

创建任务计算,它会在每个星期一的 6:05 启动计算器(计算)(如果你需要的话。)

All available commands can be found here: http://technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx

所有可用的命令都可以在这里找到:http: //technet.microsoft.com/en-us/library/cc772785%28WS.10%29.aspx

It works on windows server 2008 as well as windows server 2003.

它适用于 windows server 2008 以及 windows server 2003。

回答by s-hunter

  1. Make sure you logged on as an administratoror you have the same access as an administrator.
  2. Start->Control Panel->System and Security->Administrative Tools->Task Scheduler
  3. Action->Create Basic Task->Type a name and Click Next
  4. Follow through the wizard.
  1. 确保您以管理员身份登录或您具有与管理员相同的访问权限。
  2. 开始->控制面板->系统和安全->管理工具->任务计划程序
  3. 操作->创建基本任务-> 键入名称并单击下一步
  4. 按照向导进行操作。

回答by Alex

http://windows.microsoft.com/en-US/windows7/schedule-a-task

http://windows.microsoft.com/en-US/windows7/schedule-a-task

maybe that will help with windows scheduled tasks ...

也许这将有助于 Windows 计划任务......

回答by Rudu

There's pycronwhich I really as a Cron implementation for windows, but there's also the built in scheduler which should work just fine for what you need (Control Panel -> Scheduled Tasks -> Add Scheduled Task).

pycron,我真的作为cron实施的窗户,但也有内置的调度器应该只是罚款为您所需要的(控制面板- >任务计划- >添加任务计划)。

回答by Josh Correia

If you don't want to use Scheduled Tasksyou can use the Windows Subsystem for Linuxwhich will allow you to use cron jobs like on Linux.

如果您不想使用计划任务,您可以使用适用于 LinuxWindows 子系统,它允许您像在 Linux 上一样使用 cron 作业。

To make sure cron is actually running you can type service cron statusfrom within the Linux terminal. If it isn't currently running then type service cron startand you should be good to go.

要确保 cron 确实在运行,您可以service cron status在 Linux 终端中输入。如果它当前没有运行,那么输入service cron start你应该很高兴。