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
- crontab
- cygrunsrv
- ssmtp (for å få statusemail)
- vim (hvis ikke en versjon følger med cygwin)
Vi må også ha editoren Vi/Vim. En miniversjon av denne følger med cygwin dll.
cygwin path
GjørSET
eller echo $path
i Cygwin terminalen for å skrive ut cygwins PATH.
- PATH=/usr/local/bin;/usr/bin;/cygdrive/c/Program Files/....
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/cron.exe
/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/crontab.exe Program som administrerer cron tabellen. Brukeren kaller dette programmet når man vil endre cron tabellen, eksempelvis med crontab -l, crontab -e, crontab -r (nb - sletter hele tabellen).
- /usr/bin/cron-config This script initializes and possibly starts a cron daemon. It includes numerous tests to insure the environment is sound. On 2003 it is capable of creating a privileged user.
- /usr/bin/cronevents.exe Program for å feilsøke cron. Kjør dette dersom noe ikke fungerer.
- /usr/bin/cronbug This script produces an error report for cron. Please run it while the cron service is running (if possible).
- /usr/bin/cronlog Produces cron statusemail. Can be pointed to by /usr/sbin/sendmail.
/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).
- /bin/crontab.exe
- /bin/cron-config
- /bin/cronevents.exe
- /bin/cronbug
- /bin/cronlog
Dette ser ut til å være de samme filene som beskrevet ovenfor. Uklart hva de brukes til.
- var/cron En katalog som muligens inneholder cron tabell filen.
- /var/log/cron.log
- /var/run/cron.pid Inneholder PID for cron prosessen. Skriver man ut filen (more /var/run/cron.pid) får man et nummer. Dersom man i cygrunsrv slår av prosessen, og så skriver ut cron.pid, får man at filen ikke eksisterer. Starter man servicen kan man skrive ut PID.
- /etc/postinstall/cron.sh.done
- /etc/setup/cron.lst.gz
- /home/april/cron.log
- /home/april/cronbug.txt
- /tmp/cron.20170102_150003.8188.log
- /tmp/cron.20170102_150003.8188.log.err
- /tmp/cron.20170216_150004.9276.log
- /tmp/cron.20170216_150004.9276.log.err
- /usr/share/doc/cron
- /usr/share/doc/Cygwin/cron-4.1-65.README
- /usr/share/man/man1/crontab.1
- /usr/share/man/man5/crontab.5
- /usr/share/man/man8/cron.8
log-filer, README, etc.
Konfigurere cron
Etter installasjon er ikke cron integrert i Windows.
- Starter cron automatisk når Windows starter?
- Hvilken Windows bruker kjører cron under?
For å konfigurere cron kjører vi en av følgende kommandoer:
- cron-config
- cygrunsrv --install cron --path /usr/bin/cron.exe --args n
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.
- net start cron
- cygrunsrv --list
- cygrunsrv --list --verbose
- cygrunsrv --start cron
- cygrunsrv --stop cron
- cygrunsrv --version
- cygrunsrv --query cron
- sc
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) yesEnter 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 -removeAvinstallere cygwin
https://cygwin.fandom.com/wiki/Uninstalling_CygwinCygwin 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
- Chapter 3. Using Cygwin. POSIX accounts, permission, and security
https://cygwin.com/cygwin-ug-net/ntsec.html
- 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
- Using Cygwin sshd on a Windows Domain
https://microtechnology-services.github.io/2016/04/29/cygwin-sshd-on-windows-domain.html
- 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
- Cygwin Utilities mkpasswd
https://cygwin.com/cygwin-ug-net/mkpasswd.html
- 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
- Installing & Configuring the Cygwin Cron Service in Windows.
https://www.davidjnice.com/cygwin_cron_service.html
- Using the LocalSystem Account as a Service Logon Account
https://docs.microsoft.com/en-us/windows/desktop/ad/the-localsystem-account
- Cron and Crontab usage and examples
https://www.pantz.org/software/cron/croninfo.html
- Starting/configuring Crontab in Cygwin
https://solidlinux.wordpress.com/2010/06/28/starting-crontab-in-cygwin/
- Cron on Cygwin
http://pedroivanlopez.com/cron-on-cygwin/