Du er her: Hjem --> Annet --> Blog --> Cygwin crontab

Sette opp crontab på cygwin

Cygwin er software som gir UNIX funksjonalitet på en Windows maskin. Crontab er et UNIX program for å sette opp automatisk kjøring av andre programmer og script ved definerte tidspunkt. Eksempelvis kan man ha et backup script og sette opp dette til å kjøre hver natt klokken 02:00.

Installere Cygwin crontab

Installere cygwin cron: i tillegg til cygwin dll vi må installere pakkene

cygrunsrv gjør at UNIX daemons kan kjøre som Windows services (og kan kontrolleres fra services.msc, net use, sc, i tillegg til fra cygrunsrv).

Vi må også ha editoren Vi/Vim. En miniversjon av denne følger med cygwin dll.

cygwin path

Gjør SET eller echo $path i Cygwin terminalen for å skrive ut cygwins PATH. Det er altså bare med to UNIX kataloger. Resten er en kopi av Windows sin PATH systemvariabel. Når man kjører en UNIX kommando vil Cygwin først lete i /usr/local/bin, deretter i /usr/bin.

crontab filene på cygwin

Vi gjør et søk find / -name cron* på vår cygwin installasjon og finner følgende filer:

/usr/sbin inneholder systemfiler som ikke er kritiske for oppstart av systemet.

På UNIX er cron en daemon, altså et program som hele tiden kjører i bakgrunnen. Cron sjekker hvert minutt cron tabellen for om et program skal startes. På Cygwin kan man installere pakken cygrunsrv. Dette programmet gjør at UNIX daemons kan kjøre som Windows services. I Windows services.msc kan man administrere cron gjennom cygrunsrv (starte, stoppe, osv).

/usr/bin inneholder systemfiler som ikke er kritiske for oppstart av systemet.

crontab.exe er programmet som administrerer cron-tabellen. Eksempelvis vil crontab -l skrive ut cron tabellen. crontab -e gir mulighet til å editere cron tabellen og installere en ny cron tabell. crontab -r sletter brukerens cron tabell (så ikke kjør denne kommandoen uten at du mener det).

Dette ser ut til å være de samme filene som beskrevet ovenfor. Uklart hva de brukes til.

log-filer, README, etc.

Konfigurere cron

Etter installasjon er ikke cron integrert i Windows.

For å konfigurere cron kjører vi en av følgende kommandoer:

Før cron er konfigurert: man kan legge inn linjer i cron tabellen, men de kjøres ikke.

Det er uklart hva som er forskjellen på de to kommandoene.

Etter å ha kjørt en av disse kommndoene vises cygrunsrv i services.msc. Servicen kjører under LocalSystem kontoen. Innslagene i cron tabellen begynner å kjøre. Dersom man gjør en endring i cron tabellen må man restarte cygrunsrv for at endringen skal registreres. cygrunsrv (og cron) starter når Windows starter.

cron-config

$ cron-config
The cron daemon can run as a service or as a job. The latter is not recommended. 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) yes
Please enter the password for user 'Peder':
Reenter:
Running cron_diagnose ...
... no problem found.
INFO: A cron daemon is already 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.

cygrunsrv

cygrunsrv --install cron --path /usr/bin/cron.exe --args n

Noen steder bruker man --args D istedenfor --args n

myuser@mymachine ~
$ /usr/sbin/cron --help
cron: unknown option -- -
usage: /usr/sbin/cron [-n] [-x [ext,sch,proc,pars,load,misc,test,bit]]

cygrunsrv kan gjøre mer enn å installere en service. Se cygrunsrv --help for informasjon.

cygrunsrv - is a service starter and stopper can operate in two basic modes. The first is the 'service management' or 'commandline' mode. This allows you to install and remove a service from the system registry, or to start and stop a previously installed service. The second mode is the 'run a service' or 'daemonize' mode. This mode is reached ONLY via a special entry point called by the Windows Service Mananger -- you can't put cygrunsrv in that mode from the command line. In the 'daemonize' mode, cygrunsrv sets up the environment (according to flags set via the 'commandline' mode). It adds '/bin' to the front of the PATH so that the target service can find cygwin1.dll easily. It (optionally) redirects stdout, stdin, and stderr to log files or to the NT/W2K Event Log (event log access not yet implemented). Finally, cygrunsrv starts the target daemon.

Avinstallere service

cygrunsrv -remove

Avinstallere cygwin

https://cygwin.fandom.com/wiki/Uninstalling_Cygwin

Cygwin cron på Windows workgroup

hvis jeg endrer i crontab filen må jeg restarte cron servicen for at det skal fungere. både på Win server domenet og min lokale maskin.

Cygwin cron på Windows domene

hvis jeg endrer i crontab filen må jeg restarte cron servicen for at det skal fungere. både på Win server domenet og min lokale maskin.

Referanser

  1. Chapter 3. Using Cygwin. POSIX accounts, permission, and security
    https://cygwin.com/cygwin-ug-net/ntsec.html
  2. How do you run a crontab in Cygwin on Windows?
    https://stackoverflow.com/questions/707184/how-do-you-run-a-crontab-in-cygwin-on-windows
  3. Using Cygwin sshd on a Windows Domain
    https://microtechnology-services.github.io/2016/04/29/cygwin-sshd-on-windows-domain.html
  4. Corinna Vinschen Why you can't load ws2_32.dll (was Re: Can't use key authentication on x64 Server 2003 R2)
    https://cygwin.com/ml/cygwin/2010-01/msg00334.html
  5. Cygwin Utilities mkpasswd
    https://cygwin.com/cygwin-ug-net/mkpasswd.html
  6. I am unable to find the etc/passwd file in cygwin
    https://stackoverflow.com/questions/28573763/i-am-unable-to-find-the-etc-passwd-file-in-cygwin
  7. Installing & Configuring the Cygwin Cron Service in Windows.
    https://www.davidjnice.com/cygwin_cron_service.html
  8. Using the LocalSystem Account as a Service Logon Account
    https://docs.microsoft.com/en-us/windows/desktop/ad/the-localsystem-account
  9. Cron and Crontab usage and examples
    https://www.pantz.org/software/cron/croninfo.html
  10. Starting/configuring Crontab in Cygwin
    https://solidlinux.wordpress.com/2010/06/28/starting-crontab-in-cygwin/
  11. Cron on Cygwin
    http://pedroivanlopez.com/cron-on-cygwin/
Telefon: 67 20 71 21 / 92 60 51 57 Logo-tema