Linux crontab未执行,cron和crontab的不同用户是问题所在吗?

Linux crontab未执行,cron和crontab的不同用户是问题所在吗?,linux,cron,cygwin,crontab,Linux,Cron,Cygwin,Crontab,我正在Win7中使用cygwin 2.3.1版(0.291/5/3),并且已经尝试了几个小时来运行我的crontab计划作业。在我看来,可能存在的问题是,我的cron进程和crontab进程有不同的所有者,我不知道如何解决这个问题 我已经创建了一个crontab任务,它应该在第一分钟创建文件c:\crontest.txt,然后每分钟更新一次。这不会发生 以下是我在尝试运行此crontab时的控制台输出: User@Uva ~ $ cygrunsrv --install cron --path /

我正在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 ~ $
如上所示,PPID636的cron服务在Win7服务中也显示为PID 636,Win7将其视为正在运行

有人能看到我可能做错了什么,或者我能提供什么其他信息来帮助我工作吗?

是的

在进行了大量的挖掘和信心的飞跃之后,我发现了如何让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 ~ $