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 用戶發現這個有用
這篇文章有幫助嗎?

相關文章

如何使用 cPanel 下载备份?(视频)

使用cPanel下载备份是一个简单的过程。以下是帮助您安全下载网站备份的逐步指南: 第一步:登录cPanel 打开您的网页浏览器。...

如何生成Sapna备份并发送到FTP服务器? (视频)

生成cPanel备份并将其发送到FTP服务器是一个简单的过程。以下是具体步骤: 第1步:登录cPanel...

如何在 cPanel 中恢复备份?(视频)

在 cPanel 中恢复备份是一个简单的过程,可以高效地恢复您的网站数据。以下是恢复备份的分步指南: 第一步:登录 cPanel 打开您的网页浏览器,访问...

如何在 cPanel 中更改账户密码?(视频)

在cPanel中更改账户密码非常简单,只需几个步骤即可完成。请按照以下说明操作。 第一步:登录cPanel...

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

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