0

I have correct python3 program looking like *.py. I have Digital Ocean(DO) droplet with Ubuntu 14.04. My program post message to my twitter account. I just copy my *.py in some directory on DO droplet and run it with ssh and all works fine. But I need to post message(rum my program) automatically every 15-30 min for example.

Iam newbie with this all. What should i do? Step-by-step please!

  • 2
    Have you considered using cron? http://www.adminschoice.com/crontab-quick-reference/ – Hitesh Dharamdasani Aug 02 '14 at 21:57
  • @HiteshDharmadasani A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported. – NewbiePython Aug 02 '14 at 22:11

2 Answers2

0

First install and enable fcron. Then, sudo -s into root and run fcrontab -e. In the editor, enter */30 * * * /path/to/script.py and save the file. Change 30 to 15 if every 15 minutes is what you're after.

DrJPepper
  • 168
  • 6
0

cron is probably the way to go - it's built for this task. See this DigitalOcean tutorial for details.

This StackOverflow answer explicitly states what to put in for a 30 minute repeat interval.

If you don't want to use cron for some reason, you could do something like:

import time

# Repeat forever
while True:
    post_to_twitter() # Call your function
    # Sleep for 60 seconds / minute * 30 minutes
    time.sleep(60 * 30)
Community
  • 1
  • 1
bbayles
  • 4,389
  • 1
  • 26
  • 34
  • Thanks! Can i use other python program on this droplet while my first program «repeat forever»? What about server resources? Cron or «repeat forever» uses less? – NewbiePython Aug 03 '14 at 06:45
  • Yes, you may run other programs - see [here](http://www.cyberciti.biz/faq/linux-command-line-run-in-background/). As for resources, I imagine cron will use less. The Python program is sleeping and not doing much, though. – bbayles Aug 03 '14 at 13:09