Skip to main content
SNP-2025-0023
Home / Code Snippets / SNP-2025-0023
SNP-2025-0023  ·  CODE SNIPPET

How to Automatically Update CyberPanel Disk Usage Every Minute: A Step-by-Step Guide

General · Published: 2024-12-22 · debmedia
01
Problem Statement & Scenario
The Problem

🛠️ Step 1: Edit the Cron Job File

  1. Open the cron job editor:bashCopy codecrontab -e
  2. Add the following line to run the disk usage update every minute:bashCopy code* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py CalculateAndUpdateDiskUsage > /dev/null 2>&1
  3. Add this second line to check disk usage every minute:bashCopy code* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py checkDiskUsage > /dev/null 2>&1
  4. Save and exit:
    • Nano: Ctrl + O, then Ctrl + X
    • Vim: :wq

🛠️ Step 2: Restart Cron Service

Make sure the cron service is active and running:

bashCopy codesystemctl restart crond

Check cron service status:

bashCopy codesystemctl status crond

🛠️ Step 3: Verify Cron Jobs are Active

List all active cron jobs to verify:

bashCopy codecrontab -l

You should see:

javascriptCopy code* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py CalculateAndUpdateDiskUsage > /dev/null 2>&1
* * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py checkDiskUsage > /dev/null 2>&1

🛠️ Step 4: Monitor Logs for Errors

After a few minutes, check the CyberPanel logs:

bashCopy codetail -f /usr/local/CyberCP/debug.log

Look for any errors related to disk usage.


🛡️ Important Notes:

  • Running the script every minute can slightly increase CPU and disk usage. Monitor server performance using:bashCopy codetop
  • If you notice server slowdowns, consider reducing the frequency to every 5 minutes:bashCopy code*/5 * * * * /usr/local/CyberCP/bin/python /usr/local/CyberCP/IncBackups/IncScheduler.py

If systemctl restart crond is not working, it could mean that your server is not using crond or the service is named differently. Follow these steps to troubleshoot and resolve the issue:


🛠️ 1. Check if Cron is Installed

Run the following command to see if cron is installed:

bashCopy codecrontab -l

If it displays your cron jobs, cron is installed. If not, install it:

  • For CentOS/RHEL:bashCopy codeyum install cronie -y
  • For Debian/Ubuntu:bashCopy codeapt install cron -y

🛠️ 2. Check the Cron Service Name

The cron service might be named differently depending on your OS:

  • On CentOS/RHEL:bashCopy codesystemctl status crond
  • On Debian/Ubuntu:bashCopy codesystemctl status cron

If the service is cron instead of crond, restart it:

bashCopy codesystemctl restart cron

🛠️ 3. Enable and Start Cron Manually

If the service is stopped or disabled, enable and start it:

bashCopy codesystemctl enable crond
systemctl start crond

Or, if your system uses cron instead:

bashCopy codesystemctl enable cron
systemctl start cron

🛠️ 4. Verify Cron Service is Running

Check if the cron service is active:

bashCopy codesystemctl status crond

or

bashCopy codesystemctl status cron

If it shows active (running), your cron service is running fine.


🛠️ 5. Verify Cron Execution Manually

To ensure your cron job is working:

  1. Add a test cron job:bashCopy codecrontab -e
  2. Add the following line:bashCopy code* * * * * echo "Cron is working" >> /tmp/cron-test.log
  3. After 2 minutes, check if the log is created:bashCopy codecat /tmp/cron-test.log

If you see Cron is working, your cron setup is fine.


🛠️ 6. Restart the Server (if all else fails)

If restarting the cron service doesn’t work, a server reboot might help:

bashCopy codereboot

Final Verification

After restarting the cron service or server:

  1. Verify the cron jobs:bashCopy codecrontab -l
  2. Check the CyberPanel disk usage cron jobs:bashCopy codetail -f /usr/local/CyberCP/debug.log
  3. Monitor disk usage from the CyberPanel dashboard.
04
Real-World Usage Example
Usage Example

🛠️ Step 5: Verify Disk Usage in CyberPanel

  1. Log in to CyberPanel Dashboard.
  2. Navigate to Websites > Manage Website > Disk Usage.
  3. Confirm that the disk usage is updating every minute.

1-on-1 Technical Mentorship

Want to master snippets like this?

Debasis Bhattacharjee offers direct mentorship sessions for developers looking to level up their code quality, architecture decisions, and production engineering skills. Two decades of real-world experience — no theory, just craft.