Common Cron Job Examples
This guide provides ready-to-use cron job commands for common tasks on DirectAdmin shared hosting. Copy and paste these into your cron job configuration.
WordPress Cron
WordPress has a built-in pseudo-cron that runs on page visits. For better reliability, disable WP-Cron and use a real cron job:
- Add this to
wp-config.php:
define('DISABLE_WP_CRON', true);- Set up a cron job to run every 5 minutes:
*/5 * * * * /usr/local/bin/php /home/username/domains/yourdomain.com/public_html/wp-cron.php >/dev/null 2>&1Database Backup
Back up your MySQL database daily at 2 AM:
0 2 * * * /usr/bin/mysqldump -u dbuser -p'dbpassword' dbname > /home/username/backups/db-$(date +\%%Y\%%m\%%d).sql 2>&1Tip: Store backups outside your
public_htmldirectory so they are not accessible via the web.
Clear Cache or Temp Files
Delete files older than 7 days from a temp directory, daily at 3 AM:
0 3 * * * find /home/username/domains/yourdomain.com/public_html/cache -type f -mtime +7 -delete >/dev/null 2>&1Send Scheduled Emails (PHP Script)
Run a PHP script every hour to process an email queue:
0 * * * * /usr/local/bin/php /home/username/domains/yourdomain.com/public_html/send-emails.php >/dev/null 2>&1Laravel Task Scheduler
Laravel requires a single cron entry that runs every minute:
* * * * * cd /home/username/domains/yourdomain.com/public_html && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1Node.js Script
Run a Node.js script daily at midnight:
0 0 * * * /usr/local/bin/node /home/username/domains/yourdomain.com/scripts/cleanup.js >/dev/null 2>&1Log Rotation
Rotate application logs weekly on Sunday at 1 AM:
0 1 * * 0 mv /home/username/logs/app.log /home/username/logs/app-$(date +\%%Y\%%m\%%d).log && touch /home/username/logs/app.log >/dev/null 2>&1Checking Cron Output
To debug a cron job, redirect output to a log file:
*/5 * * * * /usr/local/bin/php /home/username/script.php >> /home/username/cron-debug.log 2>&1Then check the log:
tail -50 /home/username/cron-debug.logBest Practices
- Always use full paths for commands and scripts
- Redirect output to prevent email floods
- Test your command via SSH first before adding it as a cron job
- Avoid running resource-heavy scripts more frequently than necessary
- Use lock files to prevent overlapping runs of long-running scripts
Related Articles
Need help? Contact our support team at {{SUPPORT_EMAIL}} or open a ticket at {{SUPPORT_URL}}.