Advertisement

Advertisement

Cron Job Examples and Tip

Cron jobs are useful for scheduling commands to run periodically. For example:

  • Every 15 minutes
  • Once per month

In this guide I will show you several common cron tasks and tips that I use including:

  • Common scheduling examples
  • Chaining together multiple programs
  • Redirecting output
  • Checking logs
  • Running a script from a Python virtual environment

Cron is good for programs that run and then complete, like generating a report, but cron is not for services that stay running forever like a web server. If you want to have a program that continuously runs and you want to ensure the program stays running even if it crashes or the server restarts, you want to setup a service. Check out my tutorial on how to do that: Creating Systemd Service Files.

Cron is available in Linux and Mac operating systems, but not Windows.

How to Specify SSH key for Git repository

If you are using SSH keys with Git to clone and pull your repositories, you may have to manage several SSH keys. For example, it is common to setup a "deploy key" in GitHub (Repository | Settings | Deploy Keys) that has read-only rights. GitHub also forces you to use unique SSH deploy keys for each repository, so you have to create a unique SSH keys when you have multiple repositories.

This example shows you how to use specific SSH keys for each remote repository.

How to Create a Secure Linux System User

When deploying a production service in Linux you want to configure it as securely as possible. Ideally, you will create a unique Linux user for each service and give them only read and write permission to the exact files they need.

You can go even further and create a "system" user that has no home directory, no login shell, and no password. This prevents the user from being able to login and does not provide a home directory for them to store files.

If the service was ever compromised this limits the actions an attacker can take with the user running the service.

This example will show you how to create a system user with:

  • No home directory
  • No logn shell
  • No password (Can't login)

Open a Linux Firewall port with firewall-cmd

In Fedora/CentOS/RedHat, the firewall is on by default. This is a good secure-by-default practice. If you do not know that the firewall is on though, you may be wondering why you cannot connect to a web service that is listening on your machine and works fine locally, but external connections cannot be made.

This example will demonstrate how to open inbound ports and also check what ports, service, and zones are available on your machine.

Run Python WSGI Web App with Waitress

WSGI is the standard for running Python web applications. Gunicorn and uWSGI are great options for running WSGI apps, but they only have limited support in Windows or no support at all. Waitress is another option for running WSGI applications and it really shines in Windows because it is written purely in Python with no other dependencies. I will show you how to use Waitress to serve web application using Python WSGI.

Advertisement

Advertisement