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?
我如何让克伦工作?
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 /道路/ /掠夺”。)
63
You have two options:
你有两个选择:
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
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”
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
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
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
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
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.