How to create Cronjob via cPanel? (Video)

Creating a Cron Job via cPanel allows you to automate repetitive tasks on your hosting server, such as running scripts or performing backups at specific intervals. Here's a step-by-step guide.


Step 1: Log in to cPanel

  1. Open your web browser and go to your cPanel login page (e.g., https://yourdomain.com:2083).
  2. Enter your username and password, then click Log in.

Step 2: Access the Cron Jobs Tool

  1. In the cPanel dashboard, scroll down to the Advanced section.
  2. Click on Cron Jobs.

Step 3: Set an Email Address for Notifications (Optional)

  1. In the Cron Email section, enter your email address if you'd like to receive notifications whenever a cron job runs.
  2. Click Update Email.
    • To avoid excessive emails, consider using a command to suppress email notifications (explained below).

Step 4: Add a New Cron Job

  1. In the Add New Cron Job section, configure the following:
    • Common Settings: Use the dropdown menu to select a predefined schedule (e.g., once per day, every minute, etc.).
    • Custom Schedule: If none of the presets fit your needs, manually define the frequency:
      • Minute: Set the minute (e.g., 0 for the top of the hour or */5 for every 5 minutes).
      • Hour: Set the hour (e.g., 3 for 3:00 AM or */4 for every 4 hours).
      • Day: Set the day of the month (e.g., 1 for the 1st day of each month).
      • Month: Set the month (e.g., 1 for January or */3 for every third month).
      • Weekday: Set the day of the week (e.g., 0 for Sunday or * for all days).

Command: Enter the command to execute. This usually involves running a script or program. Examples:

  • PHP Script:  /usr/local/bin/php /home/username/public_html/cron_script.php
  • Backup Command:  tar -czf /home/username/backups/backup-$(date +\%Y-\%m-\%d).tar.gz /home/username/public_html
  • Email Suppression:  Add >/dev/null 2>&1 to the command to suppress email notifications.

                Example: /usr/local/bin/php /home/username/public_html/cron_script.php >/dev/null 2>&1


Step 5: Save the Cron Job

  1. Once you've configured the schedule and command, click Add New Cron Job.
  2. The new cron job will be added to the Current Cron Jobs list.

Step 6: Verify the Cron Job

  1. Review the Current Cron Jobs section to ensure the job is scheduled correctly.
  2. If needed, edit or delete a cron job from this section.

Tips for Managing Cron Jobs

  • Test the Command: Run the command manually via SSH before setting it as a cron job to ensure it works.
  • Use Logs: If you're troubleshooting, log the output to a file for review.

                  Example:  /usr/local/bin/php /home/username/public_html/cron_script.php >> /home/username/logs/cronlog.txt 2>&1

  • Avoid Overloading: Don’t schedule too many frequent cron jobs, as they can consume server resources.

By setting up cron jobs via cPanel, you can automate repetitive tasks efficiently, saving time and reducing manual work.

  • 142 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

Hoe download ik een back-up met behulp van cPanel? (Video)

Het downloaden van een back-up met behulp van cPanel is een eenvoudig proces. Hier is een...

Hoe kan ik een Sapna-back-up genereren en naar een FTP-server verzenden? (Video)

Het genereren van een cPanel-back-up en het verzenden naar een FTP-server is een eenvoudig...

Hoe herstel ik een backup in cPanel? (Video)

Het herstellen van een back-up in cPanel is eenvoudig en stelt u in staat om de...

Hoe verander ik het wachtwoord van een account in cPanel? (Video)

Het wijzigen van een accountwachtwoord in cPanel is eenvoudig en kan in een paar snelle...

How to update your contact information in cPanel? (Video)

Updating your contact information in cPanel is important to ensure you receive critical...