def execCmd(cmd):
r = os.popen(cmd)
text = r.read()
r.close()
return text
lasttime=time.time()
while True:
for disk in harddisks:
result=execCmd('hdparm -C '+ disk)
if 'standby' not in result:
lasttime=time.time()
if now - lasttime > 30 * 60: #大于30分钟就关机
result=execCmd('poweroff')
time.sleep(900) #15分钟检测一次