Checking file status
less than 1 minute read
filechk.py
#!/usr/bin/python
import time
import os, sys
from datetime import datetime
from commands import *
global sz, gSizes, gFiles
gFiles = ['test1_%Y%m%d.dat', 'test2_%Y%m%d.dat']
gSizes = [0,0,0,0]
print(time.strftime("%H:%M:%S ") + 'start...')
# init sizes
idx = 0
for fm in gFiles:
sz = 0
try:
fname = time.strftime(fm)
sz = os.stat(fname).st_size
if sz > 0:
gSizes[idx] = sz
print(time.strftime("%H:%M:%S ") + "Checking... [" + fname + "] [" + str(sz) + "]")
except:
print(time.strftime("%H:%M:%S ") + "Checking... [" + fname + "] [" + str(sz) + "]" + " - exception")
idx = idx + 1
while True:
idx = 0
for fm in gFiles:
sz = 0
try:
fname = time.strftime(fm)
sz = os.stat(fname).st_size
print(time.strftime("%H:%M:%S ") + "Checking... [" + fname + "] [" + str(sz) + "]")
except:
print(time.strftime("%H:%M:%S ") + "Checking... [" + fname + "] [" + str(sz) + "]" + " - exception")
if sz > gSizes[idx]:
break
idx = idx + 1
if idx != len(gFiles):
if sz > gSizes[idx]:
print(time.strftime("%H:%M:%S ") + "---> FOUND:[" + fname + "] [" + str(sz) + "]")
break
print(time.strftime("%H:%M:%S ") + "Sleeping...")
time.sleep(10)
Leave a comment