I have a droplet with Django installed and I can run a script from /home/sammy/revamp like python manage.py getimages it returns output like
Successfully found image for "6c90a52a75c5a91054937d6ab3c8cd4e.jpg"
Problem is it never runs itself from crontab -e
*/1 * * * * sammy cd /home/sammy/revamp/ && /usr/bin/python manage.py getimages >> /var/log/getimages.log
This is the last of many editing I’ve done to this log.
Btw here’s it’s code
class Command(BaseCommand):
help = 'Update images coloured to database'
def handle(self, *args, **options):
#get filenames automatically
try:
images = listdir('/home/sammy/revamp/revamp/media/new_colour')
for image_name in images:
exists = Image.objects.filter(original_image='original/'+image_name)
if exists:
image = exists[0]
image.colored_image = File( open('/home/sammy/revamp/revamp/media/new_colour/' + image_name, 'r'))
image.save()
os.remove('/home/sammy/revamp/revamp/media/new_colour/' + image_name)
self.stdout.write(self.style.SUCCESS('Successfully found image for "%s"' % image_name))
except Exception, e:
error_log = open('/home/sammy/revamp/error.log','a')
error.write(str(e) + '\n')
error.close()
It should output something to error.log but also doesn’t do this.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I’m not sure if you login to the console with root or the user sammy, but try running this command to make sure you’re setting the cronjob for the specific user:
sudo crontab -u sammy -e
Then change the cronjob to this:
*/1 * * * * /usr/bin/python /home/sammy/revamp/manage.py getimages >> /var/log/getimages.log
And you can see the error log of the cron service by looking in the syslog log:
cat /var/log/syslog | grep "CRON"
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.