Skip to content

Commit ae26dd4

Browse files
authored
크론 스케줄러 기능 구현
카페24 웹호스팅 계정 등 cron 을 제공하지 않는 계정에서 활용하면 좋습니다.
1 parent 02900d7 commit ae26dd4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

python_cron.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import time, os
2+
from datetime import datetime
3+
4+
def save_log(msg):
5+
if msg == "":
6+
return
7+
8+
now_dt = datetime.today().strftime("%Y-%m-%d %H:%M:%S")
9+
file_dt = datetime.today().strftime("%Y%m%d")
10+
11+
with open("python_cron_"+file_dt+".txt", "a") as f:
12+
f.write("["+now_dt+"] "+msg+"\n")
13+
14+
while True:
15+
now = time.localtime()
16+
now_list = list(now)
17+
hr = now_list[3]
18+
min = now_list[4]
19+
day = now_list[6] #monday: 0, sunday: 6
20+
21+
# 1min
22+
os.system("/usr/bin/php /home/cron/test.php")
23+
save_log("test.php")
24+
25+
# 2min
26+
if min % 2 == 0:
27+
os.system("")
28+
save_log("")
29+
30+
# 5min
31+
if min % 5 == 0:
32+
os.system("")
33+
save_log("")
34+
35+
# everyday 4:00 am
36+
if hr == 4 and min == 0:
37+
os.system("")
38+
save_log("")
39+
40+
# sunday 5:10 am
41+
if day == 6 and hr == 5 and min == 10:
42+
os.system("")
43+
save_log("")
44+
45+
time.sleep(60)

0 commit comments

Comments
 (0)