一些cygwin命令 .exe 的文件,因此您可以运行它们与标准的Windows计划,但其他人没有 .exe 扩展因此不可能从DOS(似乎).

例如,我想 updatedb 运行每晚。

我怎么做cron工作?

有帮助吗?

解决方案

您还需要安装cygrunsrv所以你可以设置的cron了作为Windows服务,然后运行cron-config

如果你想在cron作业发送任何输出的邮件你还需要安装任何eximssmtp(运行cron-config前。)

更多细节请/usr/share/doc/Cygwin/cron-*.README

关于未经.exe扩展程序,它们可能是某种类型的外壳脚本。如果你看一下这个文件的第一行,你可以看到你需要通过调用shell程序(例如,“#!/bin/sh用来运行它们(例如,“C:\cygwin\bin\sh.exe -l /my/cygwin/path/to/prog”),所以你也许可以从窗户调度执行它们什么程序”。)

其他提示

你有两个选择:

  1. 安装cron为windows服务,使用cygrunsrv:

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

    注意,在(非常)的旧版本的计划你需要使用而不是D-n

  2. 的'。exe'的文件的可能bash脚本,这样可以运行它们通过windows计划通过调用bash运行的脚本,例如:

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

帽尖 http://linux.subogero.com/894/cron-上的cygwin /

开始将cygwin-设置和从“系统管理员”类别添加“的cron”包。

我们将运行的cron由用户系统的服务。因此,不好的制度,需要一个主目录和外壳。的“/ etc / passwd的”文件将定义它们。

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

在启动服务:

$ 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

本地用户现在可以这样定义自己的计划任务(crontab中就可以开始您喜欢的编辑器):

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

<强>域用户:它不工作。可怜的cron是不能代表机器上的域用户运行的计划任务。但还有另一种方式:cron的也运行在系统级别的cron表中找到的东西,在“/ etc / crontab中”。因此,插入你的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*

最后约crontab项几句。它们或者是环境设置或调度命令。从上面可以看出,在Cygwin,最好创建一个可用的路径。主目录和外壳通常由“/ etc / passwd中”服用。

至于调度命令的列见手册页。

如果某些crontab项不运行,最好的诊断工具是这样的:

$ cronevents

只是想补充一点,与cron的选择似乎已经改变。需要传递-n而非-D。

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

应用说明从这个答案和它的工作 只是指出一个更副本粘贴喜欢的答案(因为Cygwin安装程序是一种反复制粘贴明智实现的)结果 点击WinLogo按钮,键入cmd.exe,右键单击它,选择“开始作为管理员”。在的 CMD 提示:

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

确保安装程序的提示不抛出任何错误...如果有 - 你可能有一些Cygwin的二进制文件运行,或者您是不是管理员的Windows,或一些怪异的错误...

现在在的 CMD PROMT:

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

或任何完整的文件路径,您可能需要对cygrunsrv.exe和 启动的cron Windows服务在cmd提示

 net start cron
在的的bash 终端运行

现在      的crontab -e

设置你cron项的示例波纹管:

        #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

我想通了,如何让Cygwin的cron服务自动运行,当我登录到Windows 7下面是我工作:

使用记事本,创建与在第一行和C:\cygwin\bin\Cygwin_launch_crontab_service_input.txt在第二行上(没有引号)内容no文件yes。这是两种反应,提示cron-config

创建与内容文件C:\cygwin\Cygwin_launch_crontab_service.bat

@echo off
C:
chdir C:\cygwin\bin
bash  cron-config < Cygwin_launch_crontab_service_input.txt

快捷方式添加到Windows启动文件夹的情况如下: Cygwin_launch_crontab_service.bat

请参阅 http://www.sevenforums.com/tutorials/1401 -startup - 程序 - change.html 如果你需要如何添加到启动帮助。顺便说一句,你可以选择在启动时添加这些,如果你想:

Cygwin的

XWin中服务器

第一个执行

C:\cygwin\Cygwin.bat

和第二个执行

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

正确的语法来安装的 的cron 中的cygwin作为Windows服务是通过的 -n 作为参数和不<强> -D

cygrunsrv --install的cron --path / usr / sbin目录/ cron的--args的 -n

<强> -D 开始时返回的使用错误的 的cron 在Cygwin的:

$

$ cygrunsrv --install的cron --path / usr / sbin目录/ cron的--args -D

$ cygrunsrv --start的cron

cygrunsrv:错误启动的服务:QueryServiceStatus:Win32错误1062:

该服务尚未启动。

$猫/var/log/cron.log

的cron:未知的选项 - d

用法:/ usr / sbin目录/ cron的[-n] [-x [分机,SCH,PROC,公园,负载,杂项,测试,比特]]

$

以下页面有一个很好的解释。

安装&在视窗配置Cygwin的Cron服务: https://www.davidjnice.com/cygwin_cron_service.html

PS 我不得不跑 Cygwin64终端我的Windows 10的PC作为管理员才能在安装 的cron 作为Windows服务。

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.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top