Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

How to Set Up and Manage Cron Jobs on Linux

Tech 1

To create a cron job that runs under your current user account, execute the following command:

crontab -e

To schedule a cron job for another system user, use the sudo command with the -u flag followed by the target username:

sudo crontab -u <username> -e

This will launch a text editor (Nano is the default on most distributions) where you can add, edit, or remove cron jobs.

Each cron job follows a strict syntax structure:

<minute> <hour> <day> <month> <weekday> <command_or_script_path>

The first five fields define the schedule recurrence, while the final field specifies the full path to the command or script you want to run.

Here are practical examples of scheduled cron jobs:

  • * * * * * /home/jake/scripts/automate_task.sh: Executes once every minute.
  • 0 * * * * /home/jake/scripts/automate_task.sh: Runs once at the start of every hour.
  • 0 0 * * * /home/jake/scripts/automate_task.sh: Triggers daily at midnight (12:00 AM).
  • 0 9,18 * * * /home/jake/scripts/automate_task.sh: Runs at 9:00 AM and 6:00 PM every day.
  • 0 9-18 * * * /home/jake/scripts/automate_task.sh: Executes hourly between 9:00 AM and 6:00 PM (inclusive) daily.
  • */10 * * * * /home/jake/scripts/automate_task.sh: Runs every 10 minutes.

After configuring your cron jobs, press Ctrl+X to exit the editor, thenn confirm the changes when prompted. The cron daemon will automatically apply the new schedule.

To view all active cron jobs for the current user, run:

crontab -l

For Linux desktop users, a more intuitive graphical option is available. On GNOME-based systems, install and use Gnome Schedule (package name: gnome-schedule), a GUI frontend that simplifies creating and managing cron jobs without using the command line.

Tags: Linux

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.