0
点赞
收藏
分享

微信扫一扫

python3 定时重启服务

转角一扇门 2022-08-09 阅读 77

import os

import time

import time

import datetime

import codecs



def get_min():


return int( time.strftime(
'
%M
', time.localtime(time.time())) )



def get_hour():


return int( time.strftime(
'
%H
', time.localtime(time.time())) )



def get_current_time():


return ( str(datetime.datetime.now().year) +
'
-
' + str(datetime.datetime.now().month) +
'
-
' + str(datetime.datetime.now().day) +
"

" + time.strftime(
'
%H:%M:%S
',time.localtime(time.time())) )


def writelog(content):


print(content)

f = codecs.open(
'
reboot.log
',
'
a
',
'
utf-8
')

f.write(content)

f.writelines(
'
\r\n
')

f.flush()


def rebootservice():

os.system(
'
net stop spooler
')

time.sleep(1)

os.system(
'
net start spooler
')



while True:


print(get_current_time())


if ( get_min() == 24
and get_hour() == 12 ):

writelog(
"
重启服务时间:
" + get_current_time())

rebootservice()

time.sleep(60)

time.sleep(10)

举报

相关推荐

0 条评论