File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments