Windows의 Cygwin에서 crontab을 어떻게 실행합니까?
일부 cygwin 명령은 .exe
파일이므로 표준 Windows 스케줄러로 실행할 수 있지만 다른 명령에는 .exe
확장자가 없으므로 DOS에서 실행할 수 없습니다 (처럼 보입니다).
예를 들어 updatedb
밤마다 달리고 싶습니다 .
크론은 어떻게 작동합니까?
또한 설치해야 cygrunsrv
당신이 다음 실행 Windows 서비스로 최대 cron을 설정할 수 있습니다 cron-config
.
크론 작업이 출력의 이메일을 보내도록하려면 exim
또는 ssmtp
(실행하기 전에) 중 하나를 설치해야합니다 cron-config
.
자세한 내용은를 참조 /usr/share/doc/Cygwin/cron-*.README
하십시오.
.exe
확장 프로그램이없는 프로그램 은 아마도 어떤 유형의 쉘 스크립트 일 것입니다. 파일의 첫 번째 줄을 보면 파일을 실행하는 데 사용해야하는 프로그램 (예 : " #!/bin/sh
")을 알 수 있으므로 셸 프로그램 (예 : " C:\cygwin\bin\sh.exe -l /my/cygwin/path/to/prog
") 을 호출하여 Windows 스케줄러에서 실행할 수 있습니다 . )
두 가지 옵션이 있습니다.
cygrunsrv를 사용하여 cron을 Windows 서비스로 설치합니다.
cygrunsrv -I cron -p /usr/sbin/cron -a -n net start cron
(아주) 오래된 버전의 cron에서는 -n 대신 -D를 사용해야합니다.
'non .exe'파일은 아마도 bash 스크립트 일 것이므로 bash를 호출하여 스크립트를 실행하여 Windows 스케줄러를 통해 실행할 수 있습니다. 예 :
C:\cygwin\bin\bash.exe -l -c "./full-path/to/script.sh"
모자 팁 http://linux.subogero.com/894/cron-on-cygwin/
cygwin-setup을 시작하고 "Admin"범주에서 "cron"패키지를 추가합니다.
SYSTEM 사용자가 cron을 서비스로 실행합니다. 따라서 불량 시스템에는 홈 디렉토리와 쉘이 필요합니다. "/ etc / passwd"파일이이를 정의합니다.
$ mkdir /root
$ chown SYSTEM:root /root
$ mcedit /etc/passwd
SYSTEM:*:......:/root:/bin/bash
서비스 시작 :
$ cron-config
Do you want to remove or reinstall it (yes/no) yes
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ] ntsec
Do you want the cron daemon to run as yourself? (yes/no) no
Do you want to start the cron daemon as a service now? (yes/no) yes
이제 로컬 사용자 는 다음과 같이 예약 된 작업을 정의 할 수 있습니다 (crontab에서 선호하는 편집기를 시작합니다).
$ crontab -e # edit your user specific cron-table HOME=/home/foo
PATH=/usr/local/bin:/usr/bin:/bin:$PATH
# testing - one per line
* * * * * touch ~/cron
@reboot ~/foo.sh
45 11 * * * ~/lunch_message_to_mates.sh
도메인 사용자 : 작동하지 않습니다. 불량 cron은 시스템의 도메인 사용자를 대신하여 예약 된 작업을 실행할 수 없습니다. 그러나 또 다른 방법이 있습니다. cron은“/ etc / crontab”의 시스템 수준 cron 테이블에있는 것들을 실행합니다. 따라서 거기에 서프를 삽입하여 SYSTEM이 자체적으로 수행하도록합니다.
$ touch /etc/crontab
$ chown SYSTEM /etc/crontab
$ mcedit /etc/crontab
HOME=/root
PATH=/usr/local/bin:/usr/bin:/bin:$PATH
* * * * * SYSTEM touch ~/cron
@reboot SYSTEM rm -f /tmp/.ssh*
마지막으로 crontab 항목에 대한 몇 마디. 환경 설정 또는 예약 된 명령입니다. 위에서 볼 수 있듯이 Cygwin에서는 사용 가능한 PATH를 만드는 것이 가장 좋습니다. 홈 디렉토리와 쉘은 일반적으로“/ etc / passwd”에서 가져옵니다.
As to the columns of scheduled commands see the manual page.
If certain crontab entries do not run, the best diagnostic tool is this:
$ cronevents
Just wanted to add that the options to cron seem to have changed. Need to pass -n rather than -D.
cygrunsrv -I cron -p /usr/sbin/cron -a -n
Applied the instructions from this answer and it worked Just to point out a more copy paste like answer ( because cygwin installation procedure is kind of anti-copy-paste wise implemented )
Click WinLogo button , type cmd.exe , right click it , choose "Start As Administrator". In cmd prompt:
cd <directory_where_i_forgot_the setup-x86_64.exe> cygwin installer:
set package_name=cygrunsrv cron
setup-x86_64.exe -n -q -s http://cygwin.mirror.constant.com -P %package_name%
Ensure the installer does not throw any errors in the prompt ... If it has - you probably have some cygwin binaries running or you are not an Windows admin, or some freaky bug ...
Now in cmd promt:
C:\cygwin64\bin\cygrunsrv.exe -I cron -p /usr/sbin/cron -a -D
or whatever full file path you might have to the cygrunsrv.exe and start the cron as windows service in the cmd prompt
net start cron
Now in bash terminal run crontab -e
set up you cron entry an example bellow:
#sync my gdrive each 10th minute
*/10 * * * * /home/Yordan/sync_gdrive.sh
# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +- - - - day of week (0 - 6) (Sunday=0)
# | | | +- - - - - month (1 - 12)
# | | +- - - - - - day of month (1 - 31)
# | +- - - - - - - hour (0 - 23)
# +--------------- minute
I figured out how to get the Cygwin cron service running automatically when I logged on to Windows 7. Here's what worked for me:
Using Notepad, create file C:\cygwin\bin\Cygwin_launch_crontab_service_input.txt
with content no
on the first line and yes
on the second line (without the quotes). These are your two responses to prompts for cron-config
.
Create file C:\cygwin\Cygwin_launch_crontab_service.bat
with content:
@echo off
C:
chdir C:\cygwin\bin
bash cron-config < Cygwin_launch_crontab_service_input.txt
Add a Shortcut to the following in the Windows Startup folder: Cygwin_launch_crontab_service.bat
See http://www.sevenforums.com/tutorials/1401-startup-programs-change.html if you need help on how to add to Startup. BTW, you can optionally add these in Startup if you would like:
Cygwin
XWin Server
The first one executes
C:\cygwin\Cygwin.bat
and the second one executes
C:\cygwin\bin\run.exe /usr/bin/bash.exe -l -c /usr/bin/startxwin.exe
The correct syntax to install cron in cygwin as Windows service is to pass -n as argument and not -D:
cygrunsrv --install cron --path /usr/sbin/cron --args -n
-D returns usage error when starting cron in cygwin:
$
$cygrunsrv --install cron --path /usr/sbin/cron --args -D
$cygrunsrv --start cron
cygrunsrv: Error starting a service: QueryServiceStatus: Win32 error 1062:
The service has not been started.
$cat /var/log/cron.log
cron: unknown option -- D
usage: /usr/sbin/cron [-n] [-x [ext,sch,proc,parc,load,misc,test,bit]]
$
Below page has a good explanation.
Installing & Configuring the Cygwin Cron Service in Windows: https://www.davidjnice.com/cygwin_cron_service.html
P.S. I had to run Cygwin64 Terminal on my Windows 10 PC as administrator in order to install cron as Windows service.
Getting updatedb to work in cron on Cygwin -- debugging steps
1) Make sure cron is installed.
a) Type 'cron' tab tab and look for completion help.
You should see crontab.exe, cron-config, etc. If not install cron using setup.
2) Run cron-config. Be sure to read all the ways to diagnose cron.
3) Run crontab -e
a) Create a test entry of something simple, e.g.,
"* * * * * echo $HOME >> /tmp/mycron.log" and save it.
4) cat /tmp/mycron.log. Does it show cron environment variable HOME
every minute?
5) Is HOME correct? By default mine was /home/myusername; not what I wanted.
So, I added the entry
"HOME='/cygdrive/c/documents and settings/myusername'" to crontab.
6) Once assured the test entry works I moved on to 'updatedb' by
adding an entry in crontab.
7) Since updatedb is a script, errors of sed and find showed up in
my cron.log file. In the error line, the absolute path of sed referenced
an old version of sed.exe and not the one in /usr/bin. I tried changing my
cron PATH environment variable but because it was so long crontab
considered the (otherwise valid) change to be an error. I tried an
explicit much-shorter PATH command, including what I thought were the essential
WINDOWS paths but my cron.log file was empty. Eventually I left PATH alone and
replaced the old sed.exe in the other path with sed.exe from /usr/bin.
After that updatedb ran to completion. To reduce the number of
permission error lines I eventually ended up with this:
"# Run updatedb at 2:10am once per day skipping Sat and Sun'
"10 2 * * 1-5 /usr/bin/updatedb --localpaths='/cygdrive/c' --prunepaths='/cygdrive/c/WINDOWS'"
Notes: I ran cron-config several times throughout this process
to restart the cygwin cron daemon.
참고URL : https://stackoverflow.com/questions/707184/how-do-you-run-a-crontab-in-cygwin-on-windows
'Programing' 카테고리의 다른 글
Android에서 GSON 또는 다른 라이브러리를 사용하지 않고 개조를 사용하여 문자열로 응답을 얻는 방법 (0) | 2020.08.26 |
---|---|
IEnumerator와 IEnumerable의 차이점은 무엇입니까? (0) | 2020.08.26 |
C # 제네릭 오류에 대한 도움말- " 'T'형식은 nullable이 아닌 값 형식이어야합니다." (0) | 2020.08.26 |
메시지 펌프 란? (0) | 2020.08.26 |
두 가지 조건을 하나로 확인하는 방법 (0) | 2020.08.26 |