개발자/Raspberry Pi

정해진 시간마다 실행하게 하는 crontab 사용하기

지구빵집 2022. 12. 30. 13:13
반응형

 

 

라즈베리 파이3 에서 crontab 을 사용한다. KT iot Makers  서버를 점검하거나 하면 웨더 스테이션을다시 리셋시켜야 정상적으로 데이터를 보낸다. 

 

그래서 항상 밤 12시 1분에 웨더 스테이션을 다시 시작하도록 설정해야 한다.

 

crontab 파일이 생성되어 있는지 확인해보자

 

 

pi@raspberrypi:~ $ crontab -l

no crontab for pi

 

암것도 없다고 한다. 

 

crontab 실행파일은 이미 설치되어 있으므로 crontab을 처음 실행하게 되면 아래처럼 에디터를 설정하는 화면이 나온다.

 

pi@raspberrypi:~ $ crontab -e

no crontab for pi - using an empty one



Select an editor.  To change later, run 'select-editor'.

  1. /bin/ed

  2. /bin/nano        <---- easiest

  3. /usr/bin/vim.tiny



Choose 1-3 [2]:

crontab: installing new crontab

pi@raspberrypi:~ $

 

여기서  crontab 파일을 수정한다. 

 

pi@raspberrypi:~ $ crontab -e 하면 nano 에디터가 실행되어 

파일이 열리는데 우리는 매일 밤 12시 1분에 재부팅하도록 설정하니 맨 아래에 다음과 같은 줄만 추가한다.

 

#은 주석이다.

 

# 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   command



#everyday night 0 si 1 boon reboot

1 0 * * * sudo reboot
 

수정했으면 ctrl-x 누르고 y 누르고 enter 를 눌러 빠져 나오면 아래와 같은 메세지가 나온다.

 

crontab: installing new crontab

pi@raspberrypi:~ $

 

자~ 이제 매일 밤에 부팅이 되어 kt 가 시스템 점검을 하더라도 다음 날이면 정상적으로 웨더 스테이션이 작동할것이다.  

 

 
Syeda Sheraj Ali @Sheraj99
 
 
 
 

 

반응형