I am using cygwin version 2.3.1(0.291/5/3) in Win7 and have been trying for hours to get my crontab scheduled job to run. In my eyes, the thing that could be an issue is that my cron process and my crontab process have different owners and I am not sure how to fix that.
I have created a crontab task that should create the file c:\\crontest.txt on the first minute and update it every minute there after. This does not happen!
Here is my console output during an attempt to get this crontab running:
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 ~ $
The cron service with PPID 636 as shown above is also shown in Win7 services as PID 636 and Win7 sees it as Running.
Can anyone see what I may be doing wrong or what other info can I provide for you to help me get this working?
Yes.
Well after much digging around and leaps of faith I found out how to make cron run as the same user as crontab.
Once they were using the same user, my crontab started working!
Basically I had to run cron-config and answer the questions correctly. There is a point where I was required to enter my Win7 user password for my 'User' account. From reading I did, it looks like this is a potential security issue but I am the only administrator on a single home network so I decided it was OK.
Here is the command sequence that got me going:
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 ~ $
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.