cron bug

Chuck Roberts croberts@gilsongraphics.com
Wed Jan 13 15:58:00 GMT 2016


> Hello,
>
> I have set up cron as below on a fresh Windows 10 with a fresh,
> minimal 64-bit Cygwin installation. Cronjobs are not executed and
cronevents says /usr/sbin/cron:
> PID 608: (CRON) error (can't switch user context). The output of
> cronbug
is attached.

>
> When I run the service not under my own user but as an administrator,
> the result and error is the same.

First I try not to make any assumptions about what the user knows about
cron. So here are some tips.

- In general, do not edit the system crontab files, instead edit your user
crontab files with 'crontab -e' where '-e' means edit. You will need an
environment variable to setup an editor like this: 'export EDITOR=nedit'.
You can put the whole path to nedit in there if need be.

So, what is the exact command you are using to edit the crontab files?

- When the cron job runs it runs in it's own shell, with no environment
variables at all, i.e. no PATH or anything. To set environment variables
add these entries to the crontab file:

PATH=/usr/bin:/sbin:/whatever
MAIL=youruser (sends email to this account)

Each time cron runs and produces output, an email is sent to the account
in the MAIL variable.

- Next, the command must include the full path to the command like this:
1 18 29 1 * /home/comp/perl/me/gocron

If gocron is a bash script which calls a Perl program, I always pass the
working directory to my Perl program inside the 'gocron' bash script. I
think I had trouble getting the current directory inside my Perl script
with $t=`pwd`;. It would work during testing outside of cron, but when it
was run by cron, pwd didn't work. I also test my bash scripts with the
'at' command, which works very much like cron, but with less typing.

The at format is: at -f FILETORUN TIMESPEC
Example: at -f /path/to/file/gocron now (run now)
Example: at -f /path/to/file/gocron + 1 minute (run 1 minute from now)
Example: at -f /path/to/file/gocron 2:05pm (runs at 2:05pm based on the
server time)


This runs my gocron bash script after 1 minute passes. See the man page
for 'at' for more info on the TIMESPEC format.



Chuck

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list