The Crontab Flask Tutorial




This tutorial briefly covers the crontab, which is what you use to run scheduled tasks automatically. The crontab works by letting you set the minute, hour, day, week, and month of the task that you wish to run.

This means you can do a couple major things. Either you can set something to run once at a very specific time repeatedly, or you can have something run every "x" amount of time.

An example might be that you run an operation once a night at midnight. Another example might be that you run something every 5 minutes.

The cron tab is defined by 5 major time settings: minutes, hours, days, weeks, and months

An example from the PythonProgramming.net crontab is:

1 * * * * sudo echo 1 > /proc/sys/vm/drop_caches

The above code means the command of "sudo echo 1 > /proc/sys/vm/drop_caches" is run every time it is the "first minute." So every hour, at the 1 minute mark after the hour, that command is run.

Another example is:

0 */12 * * * sudo python /var/www/PythonProgramming/PythonProgramming/user-data-tracking.py

The above cron job runs every 12 hours. Another version of this cron is:

0 0,12 * * * sudo python /var/www/PythonProgramming/PythonProgramming/user-data-tracking.py

Both of these crons will run every 12 hours, but the first more appropriately describes it.

If you wanted to run something at 5 minutes, 12 minutes, and 49 minutes after the hour, you would use:

5,12,49 * * * *

An easy mistake to make, like I did in the video, is to forget about the minutes asterisk. The example I gave in the video was for "every 5 hours" being:

* */5 * * *

The above example actually means "every minute of every 5 hours." To fix this, you would want to do something like:

0 */5 * * *

Now this actually runs every 5 hours. Thanks to user mulchi01 on YouTube for correcting my mistake!

The next tutorial:





  • Introduction to Practical Flask
  • Basic Flask Website tutorial
  • Flask with Bootstrap and Jinja Templating
  • Starting our Website home page with Flask Tutorial
  • Improving the Home Page Flask Tutorial
  • Finishing the Home Page Flask Tutorial
  • Dynamic User Dashboard Flask Tutorial
  • Content Management Beginnings Flask Tutorial
  • Error Handling with Flask Tutorial
  • Flask Flash function Tutorial
  • Users with Flask intro Tutorial
  • Handling POST and GET Requests with Flask Tutorial
  • Creating MySQL database and table Flask Tutorial
  • Connecting to MySQL database with MySQLdb Flask Tutorial
  • User Registration Form Flask Tutorial
  • Flask Registration Code Tutorial
  • Finishing User Registration Flask Tutorial
  • Password Hashing with Flask Tutorial
  • Flask User Login System Tutorial
  • Decorators - Login_Required pages Flask Tutorial
  • Dynamic user-based content Flask Tutorial
  • More on Content Management Flask Tutorial
  • Flask CMS Concluded Flask Tutorial
  • The Crontab Flask Tutorial
  • Flask SEO Tutorial
  • Flask Includes Tutorial
  • Jinja Templating Tutorial
  • Flask URL Converters Tutorial
  • Flask-Mail Tutorial for email with Flask
  • Return Files with Flask send_file Tutorial
  • Protected Directories with Flask Tutorial
  • jQuery with Flask Tutorial
  • Pygal SVG graphs with Flask Tutorial
  • PayPal with Flask Web Development Tutorial
  • Securing your Flask website with SSL for HTTPS using Lets Encrypt