Python crontab 사용법

1 개요[편집]

Python crontab 사용법
[root@zetawiki ~]# crontab -l
PYTHONPATH=/폴더1:/폴더2
* * * * * /절대/경로/스크립트.py

2 예시[편집]

  • 테스트 스크립트
[root@zetawiki ~]# cat /home/django/write_datetime.py
import time
t = time.time()
now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(t))
with open('/home/django/log.txt', 'a+') as f:
    f.write(now+"\n")

[root@zetawiki ~]# python /home/django/write_datetime.py
[root@zetawiki ~]# python /home/django/write_datetime.py
[root@zetawiki ~]# python /home/django/write_datetime.py
[root@zetawiki ~]# cat /home/django/log.txt
2017-02-18 00:08:26
2017-02-18 00:08:27
2017-02-18 00:08:27
  • crontab 설정
[root@zetawiki ~]# crontab -l
* * * * * python /home/django/write_datetime.py
→ 매 1분마다 write_datetime.py를 수행

3 같이 보기[편집]

4 참고[편집]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}