Eu tenho um arquivo python color.py
que eu posso chamar usando python color.py
e ele executa uma tarefa e, quando concluído, exclui um arquivo. Eu tentei adicionar um cronjob para iniciá-lo, mas nunca começa.
Aqui está o código 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()
e o comando cron
*/1 * * * * /usr/bin/python /root/images/color.py >> /var/log/color.log 2>&1