본문으로 바로가기

Ubuntu에서 스케줄러 사용하기

category Studies/Server 2022. 1. 26. 21:46

우분투에서 스케줄러를 사용하려면 crontab을 사용한다.

crontab -e

위의 명령어로 crontab 편집기를 불러오면 편집기를 선택하라는 창이 뜨는데, 나노 편집기를 선택해주도록 한다.

* * * * * command

crontab의 맨 끝 라인에 위 명령어를 추가해 스케줄을 설정할 수 있다.

* 가 의미하는 바는 다음과 같다.

* * * * *
minute
(0~59)
hour
(0~23)
day
(1~31)
month
(1~12)
day of week
(0~7)

여러 줄을 삽입하면 작업이 병렬로 실행되지만, 

메모리 등의 문제로 직렬로 실행하고 싶은 경우 다음과 같이 한다.

# Use two ampersands to run command2 after command1 has completed successfully.
02 4 * * * /path/to/command1 && /path/to/command2

허나 내가 시도했을 땐 어째선지 위의 명령어가 먹히지 않았다.

그래서 wrapper 파일을 만드는 것으로 해결했다.

 

| 참조

https://raspberrytips.com/schedule-task-raspberry-pi/#:~:text=To schedule a task on Raspberry Pi%2C there is a,specific time or on boot.&text=If you are looking to,out my e-book here.

 

How to run and schedule Python scripts on Raspberry Pi | Codementor

 

(5) cron으로 작업을 스케줄링하기 - 라즈베리 파이 문서(2021.7 이전) (wikidocs.net)

 

crontab 

[Ubuntu]Cron 그리고 Crontab (스케줄링) (tistory.com)

 

linux - cron jobs with the same execution time - Server Fault