热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在Windows上运行Cygwin中的crontab?-HowdoyourunacrontabinCygwinonWindows?

Somecygwincommandsare.exefiles,soyoucanrunthemwiththestandardWindowsScheduler,butot

Some cygwin commands are .exe files, so you can run them with the standard Windows Scheduler, but others don't have an .exe extension so can't be run from DOS (it seems like).

有些cygwin命令是.exe文件,因此可以使用标准的Windows调度器运行它们,但有些命令没有.exe扩展名,因此不能从DOS运行它们(看起来是这样的)。

For example I want updatedb to run nightly.

例如,我希望updatedb每晚运行。

How do I make cron work?

我如何让克伦工作?

7 个解决方案

#1


80  

You need to also install cygrunsrv so you can set cron up as a windows service, then run cron-config.

您还需要安装cygrunsrv,以便将cron设置为windows服务,然后运行cron-config。

If you want the cron jobs to send email of any output you'll also need to install either exim or ssmtp (before running cron-config.)

如果您希望cron作业发送任何输出的电子邮件,您还需要安装exim或ssmtp(在运行cron-config之前)。

See /usr/share/doc/Cygwin/cron-*.README for more details.

看到/usr/share/doc/Cygwin/cron-*.自述为更多的细节。

Regarding programs without a .exe extension, they are probably shell scripts of some type. If you look at the first line of the file you could see what program you need to use to run them (e.g., "#!/bin/sh"), so you could perhaps execute them from the windows scheduler by calling the shell program (e.g., "C:\cygwin\bin\sh.exe -l /my/cygwin/path/to/prog".)

对于没有.exe扩展的程序,它们可能是某种类型的shell脚本。如果您查看文件的第一行,您可以看到需要使用什么程序来运行它们(例如,“#!/bin/sh”),因此您可以通过调用shell程序(例如,“C: cygwin\bin\ bin\sh”)从windows调度器执行它们。exe - l /我的/ cygwin /道路/ /掠夺”。)

#2


63  

You have two options:

你有两个选择:

  1. Install cron as a windows service, using cygrunsrv:

    使用cygrunsrv将cron安装为windows服务:

    cygrunsrv -I cron -p /usr/sbin/cron -a -D

    cygrunsrv - cron -p /usr/sbin/cron -a -D

    net start cron

    净启动cron

  2. The 'non .exe' files are probably bash scripts, so you can run them via the windows scheduler by invoking bash to run the script, e.g.:

    “非.exe”文件可能是bash脚本,因此您可以通过调用bash来运行脚本,例如:

    C:\cygwin\bin\bash.exe -l -c "./full-path/to/script.sh"

    C:\ cygwin \ bin \ bash。exe - l - c”。/完整路径/ / script.sh”

#3


18  

hat tip http://linux.subogero.com/894/cron-on-cygwin/

帽子提示http://linux.subogero.com/894/cron-on-cygwin/

Start the cygwin-setup and add the “cron” package from the “Admin” category.

启动cygwin-setup,并从“Admin”类别中添加“cron”包。

We’ll run cron as a service by user SYSTEM. Poor SYSTEM therefore needs a home directory and a shell. The “/etc/passwd” file will define them.

我们将使用用户系统作为服务运行cron。因此,糟糕的系统需要一个主目录和一个shell。“/etc/ passby”文件将定义它们。

$ mkdir /root
$ chown SYSTEM:root /root
$ mcedit /etc/passwd
SYSTEM:*:......:/root:/bin/bash

The start the service:

启动服务:

$ cron-config
Do you want to remove or reinstall it (yes/no) yes
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ] ntsec
Do you want the cron daemon to run as yourself? (yes/no) no
Do you want to start the cron daemon as a service now? (yes/no) yes

Local users can now define their scheduled tasks like this (crontab will start your favourite editor):

本地用户现在可以像这样定义他们的预定任务(crontab将启动您最喜欢的编辑器):

$ crontab -e  # edit your user specific cron-table HOME=/home/foo
PATH=/usr/local/bin:/usr/bin:/bin:$PATH
# testing
* * * * *   touch ~/cron @reboot     ~/foo.sh 45 11 * * * ~/lunch_message_to_mates.sh

Domain users: it does not work. Poor cron is unable to run scheduled tasks on behalf of domain users on the machine. But there is another way: cron also runs stuff found in the system level cron table in “/etc/crontab”. So insert your suff there, so that SYSTEM does it on its own behalf:

域用户:它不工作。可怜的cron无法代表机器上的域用户运行调度任务。但是还有另一种方法:cron还运行在“/etc/crontab”中的系统级cron表中的内容。所以,插入你的suff,让系统代表它自己:

$ touch /etc/crontab
$ chown SYSTEM /etc/crontab
$ mcedit /etc/crontab
HOME=/root
PATH=/usr/local/bin:/usr/bin:/bin:$PATH
* * * * *   SYSTEM touch ~/cron
@reboot     SYSTEM rm -f /tmp/.ssh*

Finally a few words about crontab entries. They are either environment settings or scheduled commands. As seen above, on Cygwin it’s best to create a usable PATH. Home dir and shell are normally taken from “/etc/passwd”.

最后是关于crontab条目的几句话。它们要么是环境设置,要么是预定的命令。如上所示,在Cygwin上,最好创建一个可用的路径。Home dir和shell通常取自" /etc/passwd "。

As to the columns of scheduled commands see the manual page.

关于计划命令的列,请参阅手册页。

If certain crontab entries do not run, the best diagnostic tool is this:

如果某些crontab条目不运行,最好的诊断工具是:

$ cronevents

#4


7  

Just wanted to add that the options to cron seem to have changed. Need to pass -n rather than -D.

只是想补充一点,cron的选项似乎已经改变了。需要通过-n而不是-D。

cygrunsrv -I cron -p /usr/sbin/cron -a -n

cygrunsrv - cron -p /usr/sbin/cron -a -n

#5


3  

Applied the instructions from this answer and it worked Just to point out a more copy paste like answer ( because cygwin installation procedure is kind of anti-copy-paste wise implemented )
Click WinLogo button , type cmd.exe , right click it , choose "Start As Administrator". In cmd prompt:

应用了这个答案的说明,它只需要指出更多的复制粘贴就可以了(因为cygwin安装过程是一种防复制粘贴的实现)点击WinLogo按钮,输入cmd。exe,右键单击,选择“Start As Administrator”。在cmd提示:

 cd  cygwin installer:
 set package_name=cygrunsrv cron
 setup-x86_64.exe -n -q -s http://cygwin.mirror.constant.com -P %package_name%

Ensure the installer does not throw any errors in the prompt ... If it has - you probably have some cygwin binaries running or you are not an Windows admin, or some freaky bug ...

确保安装程序不会在提示中抛出任何错误…如果有的话——你可能有一些cygwin二进制文件在运行,或者你不是Windows管理员,或者是某个古怪的bug……

Now in cmd promt:

现在在cmd promt:

 C:\cygwin64\bin\cygrunsrv.exe -I cron -p /usr/sbin/cron -a -D   

or whatever full file path you might have to the cygrunsrv.exe and start the cron as windows service in the cmd prompt

或者任何你可能有到cygrunsrv的完整文件路径。exe并在cmd提示符中启动cron作为windows服务

 net start cron

Now in bash terminal run crontab -e

现在在bash终端运行crontab -e

set up you cron entry an example bellow:

为你树立一个榜样,下面是一个例子:

        #sync my gdrive each 10th minute
    */10 * * * * /home/Yordan/sync_gdrive.sh

    # * * * * * command to be executed
    # - - - - -
    # | | | | |
    # | | | | +- - - - day of week (0 - 6) (Sunday=0)
    # | | | +- - - - - month (1 - 12)
    # | | +- - - - - - day of month (1 - 31)
    # | +- - - - - - - hour (0 - 23)
    # +--------------- minute

#6


3  

I figured out how to get the Cygwin cron service running automatically when I logged on to Windows 7. Here's what worked for me:

当我登录到Windows 7时,我知道如何让Cygwin cron服务自动运行。这就是我的工作:

Using Notepad, create file C:\cygwin\bin\Cygwin_launch_crontab_service_input.txt with content no on the first line and yes on the second line (without the quotes). These are your two responses to prompts for cron-config.

使用记事本,创建文件C:\cygwin\bin\Cygwin_launch_crontab_service_input。txt,第一行的内容为no,第二行为yes(没有引号)。这是您对cron-config提示符的两个响应。

Create file C:\cygwin\Cygwin_launch_crontab_service.bat with content:

创建文件C:\ cygwin \ Cygwin_launch_crontab_service。蝙蝠与内容:

@echo off
C:
chdir C:\cygwin\bin
bash  cron-config 

Add a Shortcut to the following in the Windows Startup folder: Cygwin_launch_crontab_service.bat

在Windows启动文件夹中为以下添加快捷方式:Cygwin_launch_crontab_service.bat

See http://www.sevenforums.com/tutorials/1401-startup-programs-change.html if you need help on how to add to Startup. BTW, you can optionally add these in Startup if you would like:

如果您需要关于如何添加到Startup的帮助,请参见http://www.sevenforums.com/tutorials/1401-startup-programs-change.html。顺便说一句,如果你想:

Cygwin

Cygwin

XWin Server

XWin服务器

The first one executes

第一个执行

C:\cygwin\Cygwin.bat

and the second one executes

第二个执行

C:\cygwin\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe

#7


0  

Getting updatedb to work in cron on Cygwin -- debugging steps
1) Make sure cron is installed.
 a) Type 'cron' tab tab and look for completion help.
   You should see crontab.exe, cron-config, etc.  If not install cron using setup.
2) Run cron-config.  Be sure to read all the ways to diagnose cron.
3) Run crontab -e
 a) Create a test entry of something simple, e.g.,
   "* * * * * echo $HOME >> /tmp/mycron.log" and save it.
4) cat /tmp/mycron.log.  Does it show cron environment variable HOME
   every minute?
5) Is HOME correct?  By default mine was /home/myusername; not what I wanted.
   So, I added the entry
   "HOME='/cygdrive/c/documents and settings/myusername'" to crontab.
6) Once assured the test entry works I moved on to 'updatedb' by
   adding an entry in crontab.
7) Since updatedb is a script, errors of sed and find showed up in
   my cron.log file.  In the error line, the absolute path of sed referenced
   an old version of sed.exe and not the one in /usr/bin.  I tried changing my
   cron PATH environment variable but because it was so long crontab
   considered the (otherwise valid) change to be an error.  I tried an
   explicit much-shorter PATH command, including what I thought were the essential
   WINDOWS paths but my cron.log file was empty.  Eventually I left PATH alone and
   replaced the old sed.exe in the other path with sed.exe from /usr/bin.
   After that updatedb ran to completion.  To reduce the number of
   permission error lines I eventually ended up with this:
   "# Run updatedb at 2:10am once per day skipping Sat and Sun'
   "10 2  *  *  1-5  /usr/bin/updatedb --localpaths='/cygdrive/c' --prunepaths='/cygdrive/c/WINDOWS'"

Notes: I ran cron-config several times throughout this process
       to restart the cygwin cron daemon.

推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 本文深入探讨了Linux系统中网卡绑定(bonding)的七种工作模式。网卡绑定技术通过将多个物理网卡组合成一个逻辑网卡,实现网络冗余、带宽聚合和负载均衡,在生产环境中广泛应用。文章详细介绍了每种模式的特点、适用场景及配置方法。 ... [详细]
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 本文详细介绍了如何在CentOS 7操作系统上安装和配置Grafana,包括必要的依赖项安装、插件管理以及服务启动等步骤。 ... [详细]
  • 基于KVM的SRIOV直通配置及性能测试
    SRIOV介绍、VF直通配置,以及包转发率性能测试小慢哥的原创文章,欢迎转载目录?1.SRIOV介绍?2.环境说明?3.开启SRIOV?4.生成VF?5.VF ... [详细]
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • Linux 系统启动故障排除指南:MBR 和 GRUB 问题
    本文详细介绍了 Linux 系统启动过程中常见的 MBR 扇区和 GRUB 引导程序故障及其解决方案,涵盖从备份、模拟故障到恢复的具体步骤。 ... [详细]
  • 尽管某些细分市场如WAN优化表现不佳,但全球运营商路由器和交换机市场持续增长。根据最新研究,该市场预计在2023年达到202亿美元的规模。 ... [详细]
  • 本文详细分析了Hive在启动过程中遇到的权限拒绝错误,并提供了多种解决方案,包括调整文件权限、用户组设置以及环境变量配置等。 ... [详细]
  • 本文详细记录了在银河麒麟操作系统和龙芯架构上使用 Qt 5.15.2 进行项目打包时遇到的问题及解决方案,特别关注于 linuxdeployqt 工具的应用。 ... [详细]
  • 根据最新发布的《互联网人才趋势报告》,尽管大量IT从业者已转向Python开发,但随着人工智能和大数据领域的迅猛发展,仍存在巨大的人才缺口。本文将详细介绍如何使用Python编写一个简单的爬虫程序,并提供完整的代码示例。 ... [详细]
  • 本文介绍了如何利用npm脚本和concurrently工具,实现本地开发环境中多个监听服务的同时启动,包括HTTP服务、自动刷新、Sass和ES6支持。 ... [详细]
author-avatar
双子宝贝鱼
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有