개발관련일지

ubuntu 18.04 LTS - crontab 설정 본문

개발기록/LINUX

ubuntu 18.04 LTS - crontab 설정

BEECHANGBOT 2020. 4. 20. 17:41

파이썬 beautifulSoup을 사용하여 뉴스 기사를 크롤링하는 파일을 특정 주기마다 실행 시키는 방법이 필요했다.

 

cron - 특정 시간이나 특정 시간 마다 해당 작업을 자동으로 스케줄링을 수행해주는 명령어, 도구 

 

crontab - cron작업을 설정하는 파일을 crontab 파일이라함 

 

동작방식 - cron이 부팅시 실행 > 데몬으로 백그라운드 실행 > 이벤트를 대기하다가 예정된 명령 실행

 

crontab관련 파일 위치 -

/usr/bin/crontab = 사용자별 크론탭 파일들 관리

/etc/crontab = 시스템 크론탭 파일

 

crontab 명령어 -

crontab -l  >> 현재 등록되어져 있는 crontab 작업을 확인

crontab -e >> crontab의 설정된 편집기로 현재 사용자의 cron 작업을 확인 /  수정

crontab -r >> 사용자의 예약 작업을 모두 삭제

 

내가 설정해논 cron작업

root@ubuntu:# crontab -e

# Edit this file to introduce tasks to be run by cron.

# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task

# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.

# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).

# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

# For more information see the manual pages of crontab(5) and cron(8)

# m h  dom mon dow   comman

#SHELL =  /bin/bash
#PATH = /sbin:/bin:/usr/sbin:/usr/bin
#HOME = /

0 15 * * 1-5 cd 파일위치 && /usr/bin/python3.6 get_news.py

 

시간 설정 - 나의 경우엔 15:00 평일에 크론작업 수행으로 설정

* 분 - (0 - 59)

* 시 - (0 - 23)

* 일 - (1 - 31)

* 월 - (1 - 12)

* 요일 - (0 - 6)  > 0이 일요일 

 

 

 

'개발기록 > LINUX' 카테고리의 다른 글

APACHE2] 시작명령어 에러  (0) 2020.05.08
vscode romote development ec2와 연결  (0) 2020.05.06
LINUX ] 디렉토리 소유권 변경하기  (0) 2020.04.22