crontab 没有执行,cron 和 crontab 的用户是否不同?

crontab not executing, is different user for cron and crontab the issue?

我在 Win7 中使用的是 cygwin 版本 2.3.1(0.291/5/3),并且已经尝试了几个小时才能让我的 crontab 计划作业达到 运行。在我看来,可能成为问题的是我的 cron 进程和我的 crontab 进程有不同的所有者,我不确定如何解决这个问题。

我创建了一个 crontab 任务,它应该在第一分钟创建文件 c:\crontest.txt 并在之后每分钟更新一次。这不会发生!

这是我尝试获取此 crontab 时的控制台输出 运行ning:

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将其视为运行。

任何人都可以看到我可能做错了什么,或者我可以提供哪些其他信息来帮助我完成这项工作?

是的。

好吧,经过大量的挖掘和信仰的飞跃,我发现了如何使 cron 运行 成为与 crontab 相同的用户。

一旦他们使用同一个用户,我的 crontab 就开始工作了!

基本上我必须 运行 cron-config 并正确回答问题。有时我需要为我的 'User' 帐户输入我的 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 ~ $