AI SW & MLOps/Linux

crontab

S_sun 2025. 11. 27. 14:08
  • 특정 시간에 특정 작업을 실행
  1. 주기 결정
    • 분(0-59) 시간(0-23) 일(1-31) 월(1-12) 요일(0-7 : 일-월)
# 매분 실행
* * * * * /home/script/test.sh

# 특정 시간 실행
# 매주 금요일 오전 5시 45분에 test.sh 를 실행
45 5 * * 5 /home/script/test.sh

# 반복 실행
# 매일 매시간 0분, 20분, 40분에 test.sh 를 실행
0,20,40 * * * * /home/script/test.sh

# 범위 실행
# 매일 1시 0분부터 30분까지 매분 tesh.sh 를 실행
0-30 1 * * * /home/script/test.sh

# 간격 실행
# 매 10분마다 test.sh 를 실행
*/10 * * * * /home/script/test.sh

# 조금 복잡하게 실행
# 5일에서 6일까지 2시,3시,4시에 매 10분마다 test.sh 를 실행
*/10 2,3,4 5-6 * * /home/script/test.sh

 

2. 로깅

  • 해당 처리 내역에 대해 로그를 남기기
# 파일이 갱신될때마다 어떻게 처리되었는지 확인
* * * * * /home/script/test.sh > /home/script/test.sh.log 2>&1

# 자주 실행되고 지속적으로 로깅되어야 한다면
* * * * * /home/script/test.sh >> /home/script/test.sh.log 2>&1

# 로그가 필요 없을 경우
* * * * * /home/script/test.sh > /dev/null 2>&1

 

 

3. crondtab backup

crontab -l > /home/bak/crontab_bak.txt

# 자동화
50 23 * * * crontab -l > /home/bak/crontab_bak.txt

 

728x90
반응형

'AI SW & MLOps > Linux' 카테고리의 다른 글

find  (0) 2025.11.27
Shell Command  (0) 2025.11.25
[Linux] starbucks 데이터 넣기  (1) 2024.06.04
[Linux] 데이터 가져오기 & MariaDB 설치  (0) 2024.06.04
[Linux] Jupyter 설치 및 설정 & vim  (0) 2024.06.04