color.py
我有一个可以调用的python 文件python color.py
,它执行一项任务,完成后会删除一个文件。我尝试添加一个 cronjob 来启动它,但它从未启动过。
以下是 Python 代码
def colour_images(images=None):
try:
if images == None:
images = list_files()
failed = open('failed.txt')
failed_files = [x.replace('\n','') for x in failed.readlines()]
for filename in failed_files:
if filename in images:
images.remove(filename)
#print "Conversion starting total: {0} images".format(len(images))
#counter = len(images)
#check if there's a lock
try:
proccess_locked = open('memory.lock')
proccess_locked.close()
locked = True
except IOError:
locked = False
if locked == False:
lock = open('memory.lock','w')
lock.close()
for image in images:
new_name = "coloured/" + image
result = os.system("th colorize.lua {0} {1}".format(image, new_name))
os.system('rsync {0} [email protected]:/home/sammy/revamp/revamp/media/new_colour/'.format(new_name))
os.remove(new_name)
if result != 0:
failed = open('failed.txt', 'a')
failed.write(image+'\n')
failed.close()
else:
os.remove(image)
#counter -= 1
#print "{0} remaining".format(counter)
#print "{0} -> {1}".format(image, new_name)
os.remove("memory.lock")
except Exception, e:
log_error = ('error.log','w')
log.write(str(e)+'\n')
log.close()
if __name__ == '__main__':
colour_images()
和 cron 命令
*/1 * * * * /usr/bin/python /root/images/color.py >> /var/log/color.log 2>&1