需求:
1.判断操作系统类型,执行重启指令
2.支持日期判断,非周末不重启
代码
# -*- coding: utf-8 -*-
#_auther_ liu
import platform
from os import system
import time
import datetime
#判断交易日后重启机器
if __name__ == '__main__':
date = datetime.datetime.now()
#获取档期日期是星期几,返回数字
print date.isoweekday()
if date.isoweekday() == 6 or date.isoweekday() == 7:
print ("周末,允许重启设备!!!")
sysstr = platform.system()
if (sysstr == "Windows"):
print ("Windows")
system("shutdown -r -t 3")
elif (sysstr == "Linux"):
print ("Linux")
system("reboot")
else:
print ("未知操作系统类型,无法重启!!!")
else:
print ("非周末,不允许重启设备!!!")