我在Win7中使用cygwin版本2.3.1(0.291 / 5/3)并且已经尝试了几个小时来运行我的crontab预定作业。在我看来,问题可能是我的cron进程和我的crontab进程有不同的所有者,我不知道如何解决这个问题。
我创建了一个crontab任务,它应该在第一分钟创建文件c:\ crontest.txt并在之后每分钟更新一次。这不会发生!
这是我尝试运行此crontab时的控制台输出:
User@Uva ~ $ cygrunsrv --install cron --path /usr/sbin/cron --args -n
User@Uva ~ $ cygrunsrv --start cron
User@Uva ~ $ ps -al
PID PPID PGID WINPID TTY UID STIME COMMAND
10856 11196 11196 1360 pty0 197608 14:51:33 /usr/bin/rsync
2120 1 2120 2120 ? 18 Dec 8 /usr/bin/cygrunsrv
8256 8304 8256 8808 pty0 197608 02:00:54 /usr/bin/bash
S 6848 2940 2940 684 pty1 197608 19:58:41 /usr/bin/vi
S 4408 1 10840 11008 pty1 197608 20:00:54 /usr/bin/vi
11196 8256 11196 8188 pty0 197608 14:51:31 /usr/bin/bash
12240 1 12240 12240 ? 197608 19:58:05 /usr/bin/mintty
7284 12240 7284 6396 pty1 197608 19:58:06 /usr/bin/bash
S 2940 7284 2940 6360 pty1 197608 19:58:41 /usr/bin/crontab
6764 10856 11196 4696 pty0 197608 14:51:33 /usr/bin/ssh
216 1 216 216 ? 197608 19:58:07 /usr/bin/ssh-agent
11420 11196 11196 236 pty0 197608 14:51:33 /usr/bin/tee
8512 1 8512 8512 ? 197608 02:00:55 /usr/bin/ssh-agent
636 1 636 636 ? 18 22:14:14 /usr/bin/cygrunsrv
11292 636 11292 8092 ? 18 22:14:15 /usr/sbin/cron
13048 7284 13048 13044 pty1 197608 22:14:25 /usr/bin/ps
8304 1 8304 8304 ? 197608 02:00:54 /usr/bin/mintty
User@Uva ~ $ ps -ef | grep cron | grep -v grep
User 2940 7284 pty1 19:58:41 /usr/bin/crontab
SYSTEM 11292 636 ? 22:14:15 /usr/sbin/cron
User@Uva ~ $ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.dl91rLtszY installed on Wed Dec 9 22:07:56 2015)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
* * * * * echo "Cron test at $(date +\%k:\%M)" >> /cygdrive/c/crontest.txt 2>&1
User@Uva ~ $
如上所示,PPID 636的cron服务也显示在Win7服务中,因为PID 636和Win7将其视为正在运行。
任何人都可以看到我可能做错了什么,或者我可以为您提供哪些其他信息来帮助我实现这项工作?
答案 0 :(得分:0)
是
经过多次挖掘和信仰的飞跃之后,我发现了如何让cron像crontab一样运行。
一旦他们使用同一个用户,我的crontab就开始工作了!
基本上我必须运行cron-config并正确回答问题。有一点我需要为我的“用户”帐户输入我的Win7用户密码。从我做过的阅读,看起来这是一个潜在的安全问题,但我是单一家庭网络上的唯一管理员,所以我认为它没问题。
这是让我走的命令序列:
User@Uva ~ $ cron-config
The cron daemon can run as a service or as a job. The latter is not recommended.
Cron is already installed as a service under account LocalSystem.
Do you want to remove or reinstall it? (yes/no) yes
OK. The cron service was removed.
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ] ntsec
You must decide under what account the cron daemon will run.
If you are the only user on this machine, the daemon can run as yourself.
This gives access to all network drives but only allows you as user.
To run multiple users, cron must change user context without knowing
the passwords. There are three methods to do that, as explained in
http://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-nopasswd1
If all the cron users have executed "passwd -R" (see man passwd),
which provides access to network drives, or if you are using the
cyglsa package, then cron should run under the local system account.
Otherwise you need to have or to create a privileged account.
This script will help you do so.
Do you want the cron daemon to run as yourself? (yes/no) no
Were the passwords of all cron users saved with "passwd -R", or
are you using the cyglsa package ? (yes/no) no
Finding or creating a privileged user.
The following accounts were found: 'cyg_server' .
This script plans to use account cyg_server.
Do you want to use another privileged account name? (yes/no) yes
Enter the other name: User
Reenter: User
Account User already exists. Checking its privileges.
INFO: User is a valid privileged account.
INFO: The cygwin user name for account User is User.
Please enter the password for user 'User':
Reenter:
Running cron_diagnose ...
... no problem found.
Do you want to start the cron daemon as a service now? (yes/no) yes
OK. The cron daemon is now running.
In case of problem, examine the log file for cron,
/var/log/cron.log, and the Windows event log (using /usr/bin/cronevents)
for information about the problem cron is having.
Examine also any cron.log file in the HOME directory
(or the file specified in MAILTO) and cron related files in /tmp.
If you cannot fix the problem, then report it to cygwin@cygwin.com.
Please run the script /usr/bin/cronbug and ATTACH its output
(the file cronbug.txt) to your e-mail.
WARNING: PATH may be set differently under cron than in interactive shells.
Names such as "find" and "date" may refer to Windows programs.
User@Uva ~ $ ps -ef | grep cron | grep -v grep
User 2944 11780 ? 03:31:10 /usr/sbin/cron
User 2940 7284 pty1 19:58:41 /usr/bin/crontab
User@Uva ~ $