WeWP
ComparePricingFeaturesContact UsLoginTry For Free
  • Knowledge Base
  • How to Fix "Not Secure" or "Not Private" Connection Errors
  • How to Add Cron Jobs
  • Connect to Your Server via SSH on Windows
  • Keeping Servers and Sites Secure
  • Troubleshooting Cloudflare Issues
  • Install WordPress Themes and Plugins with Composer
  • How To Fix Mixed Content Issue For WordPress
  • What Is a DDoS Attack and How to Prevent It?
  • How to Enable WordPress Debug Mode
  • How to Fix the “MySQL server has gone away” Error
  • How to Configure WP Mail SMTP Plugin to Send Emails
  • How To Fix the “HSTS Missing From HTTPS Server” Error
  • How to Check Your Domain's Expiration Date
  • How to Use and Serve WebP Images in WordPress
  • Email security best practices for using SPF, DKIM, and DMARC
  • What is a LEMP (Linux, Nginx, MySql, PHP) Stack?
  • Deploying Web Applications with NGINX HTTP Server
  • How to Configure WP Rocket Plugin for WordPress
  • How to Check SPF and DKIM Records with WeWP
  • Understanding FTP vs SFTP: Which Should You Use for Secure File Transfers?
  • What is a DMARC record and How to Set it Up?
  • How to Set Up Cloudflare’s Free CDN for WordPress
  • How to check your Ubuntu version (Using the command line and GUI)
  • How to Download Backups from WeWP panel
  • How to Change the PHP Version of Your Hosting Plan
  • Troubleshooting Cloudflare Universal SSL
  • How to Fix “Your Domain Is Not Pointing” Error
  • SSH vs SSL: What’s the Difference?
  • WordPress Search and Replace
  • How to Force HTTPS on WordPress Websites
  • How to Fix a Failed Lifetime SSL Installation
  • How to Redirect HTTP to HTTPS
  • How to Monitor System Processes Using htop Command
  • Varnish vs Nginx FastCGI Cache: Which is Best for WordPress?
  • What Is the Database information_schema on phpMyAdmin?
  • How to Disable WP-Cron for Faster Performance
  • How to fix the ERR_SSL_PROTOCOL_ERROR
  • How to fix the NET::ERR_CERT_AUTHORITY_INVALID error
  • How to Add Expires Headers in WordPress
  • How to fix the “There has been a critical error on your website” error
  • How to Fix ERR_QUIC_PROTOCOL_ERROR in Chrome Browser
  • What Is Localhost? And How Does It Apply to WordPress?
  • How to Fix a Mixed Content Warning on Your Website
  • How to Fix the "Connection Timed Out" Error in WordPress
Powered by GitBook
On this page
  • What are Cron Jobs?
  • Non-Root Cron Job
  • Root Cron Job

Was this helpful?

How to Add Cron Jobs

What are Cron Jobs?

Cron jobs are a way to schedule tasks to run at specific times or intervals on a Unix-based system (like Linux). These tasks can be anything from running scripts, executing commands, or performing system maintenance automatically, without needing manual intervention each time.

Understanding Cron:

Scheduler - Managing Scheduled Tasks:

Cron acts as a scheduler for your computer, allowing you to automate tasks at specific times or intervals. The name "cron" is derived from "chronos," the Greek word for time, highlighting its function in managing time-based operations.

Configuration - Using Crontab:

Cron jobs are set up and managed through a special file called a crontab, which stands for "cron table." Each user on a Unix-based system (like Linux) has their own crontab file where they can define scheduled tasks.

To access and edit your crontab, you use the crontab command. For example:

crontab -e: Edit your crontab file.

crontab -l: View the contents of your crontab file.

Timing - Defining the Schedule:

The timing of a cron job is specified using a pattern that includes the minute, hour, day of the month, month, and day of the week when the task should be executed. This timing is set using specific values and wildcards (*) within the crontab file.

The structure of a cron job line is:

* * * * * command_to_run

Where:

  • The first * represents the minute (0-59).

  • The second * represents the hour (0-23).

  • The third * represents the day of the month (1-31).

  • The fourth * represents the month (1-12).

  • The fifth * represents the day of the week (0-6, where 0 is Sunday).

  • For example:

0 1 * * * /path/to/script.sh

This cron job will run the script /path/to/script.sh at 1:00 AM (hour 1, minute 0) every day.

Additional Notations:

  • Use specific numbers to target exact times (e.g., 0 12 * * 1-5 for 12:00 PM every weekday).

  • Use */n to specify intervals (e.g., */15 * * * * for every 15 minutes).

  • Multiple values can be specified with commas (e.g., 0 0 1,15 * * for the 1st and 15th of every month at midnight).

  • Understanding how to configure and schedule tasks using cron allows for powerful automation of routine processes on Unix-based systems. Remember to carefully test and monitor cron jobs to ensure they perform as expected.

Non-Root Cron Job

  1. Log In as Your Site User: Use SSH to connect to your server using the username associated with your website or application.

  2. Open the Cron Job Editor: Once logged in, type crontab -e to open the cron job editor. If it's your first time, it might prompt you to choose an editor. Select option 1 for Nano, which is easy to use.

  3. Add Your Cron Job Command: In the editor, add your cron job command on a new line. This command is what you want to run automatically according to a schedule.

  4. Save and Exit: To save your changes and exit Nano (or your chosen editor), press Ctrl or Cmd + X, then type Y to confirm, and press Enter.

For example, this command runs a bash script in the root of a site every 12 hours and doesn’t save or send output:

* */12 * * * cd /sites/mysite.com/files/; sh example-script.sh >/dev/null 2>&1

Root Cron Job

  1. Log In as Your Sudo User: Use SSH to connect to your server using the username of your sudo user.

  2. Edit Root's Cron Tab: Once logged in, enter the command sudo crontab -u root -e to edit the root user's cron tab. You'll be prompted to enter your sudo user password.

  3. Choose an Editor: If it's your first time editing root's cron tab, you'll be asked to choose an editor. Select option 1 for Nano, which is beginner-friendly.

  4. Add Your Cron Job: In the editor, add your cron job command on a new line. This command will run with root permissions according to the schedule you set.

  5. Save and Exit: To save your changes and exit Nano (or your chosen editor), press Ctrl or Cmd + X, then type Y to confirm, and press Enter.

That's it! You've successfully added a cron job that requires root permissions. Remember to use this approach responsibly and ensure that the commands you schedule are necessary and safe to run with root privileges.

PreviousHow to Fix "Not Secure" or "Not Private" Connection ErrorsNextConnect to Your Server via SSH on Windows

Last updated 1 year ago

Was this helpful?

Here's a simplified breakdown of what you need to do to add a non-root cron job. If you're unsure about the command syntax or schedule, you can use a cron job generator tool to help you out.

https://crontab-generator.org/