Scheduler Tasks & Cron Jobs

Automate recurring tasks on Linux and Windows servers using cron jobs, cPanel scheduling, and Plesk task scheduler.

What Are Scheduled Tasks?

Scheduled tasks (called cron jobs on Linux) are automated commands that run at specified intervals. They're used for backups, database cleanup, sending newsletters, fetching external data, and any task that needs to run on a regular schedule without manual intervention.

Linux Cron Job Syntax

The crontab syntax uses five time fields followed by the command to execute:

# Crontab format:
# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── day of week (0-7, 0 and 7 = Sunday)
# │ │ │ │ │
# * * * * * command_to_execute

Common Cron Examples

# Every 5 minutes
*/5 * * * * /usr/bin/php /home/user/public_html/cron.php

# Every hour at minute 0
0 * * * * /home/user/scripts/hourly-task.sh

# Every day at 2:30 AM
30 2 * * * /usr/bin/php /home/user/public_html/backup.php

# Every Monday at 9:00 AM
0 9 * * 1 /home/user/scripts/weekly-report.sh

# First day of every month at midnight
0 0 1 * * /usr/bin/mysqldump -u user -p'pass' dbname > /home/user/backups/db-$(date +\%Y\%m\%d).sql

# Every weekday (Mon-Fri) at 6 PM
0 18 * * 1-5 /home/user/scripts/end-of-day.sh

Managing Crontab

# Edit your crontab
crontab -e

# List current cron jobs
crontab -l

# Remove all cron jobs (use with caution!)
crontab -r

cPanel Cron Job Setup

Navigate to Cron Jobs

In cPanel, go to Advanced → Cron Jobs.

Set the Schedule

Use the "Common Settings" dropdown for presets, or fill in the five time fields manually.

Enter the Command

Use the full path to both the PHP binary and your script:

/usr/local/bin/php /home/username/public_html/cron.php

Or use wget or curl to trigger a URL:

/usr/bin/curl -s https://yourdomain.com/cron.php > /dev/null 2>&1

Plesk Scheduled Tasks (Windows)

For configuring scheduled tasks in Plesk on Windows servers, use the following executable and argument paths:

ASPX Files

Executable:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

Argument:
-c "(new-object system.net.webclient).downloadstring('http://domain.tld/path/file_name')"

PHP Files

Executable:
C:\Program Files (x86)\Parallels\Plesk\Additional\PleskPHP54\php-cgi.exe

Argument:
G:\PleskVhosts\domain.tld\path\file_name
Shared Hosting Limitation

If you are on a shared hosting environment, you may not be able to parse .exe or .vb files. In such cases, convert your scripts to .php or .aspx formats instead.

Cron Job Logging & Debugging

When a cron job fails silently, logging is essential for diagnosis:

# Log output to a file
*/5 * * * * /usr/bin/php /home/user/cron.php >> /home/user/logs/cron.log 2>&1

# Email output (set MAILTO at top of crontab)
MAILTO=admin@yourdomain.com
0 * * * * /home/user/scripts/hourly.sh

# Log with timestamp
*/5 * * * * echo "$(date): Starting cron" >> /home/user/logs/cron.log && /usr/bin/php /home/user/cron.php >> /home/user/logs/cron.log 2>&1

Common Cron Issues

  • Wrong PHP path — use which php to find the correct binary path
  • Permission denied — ensure the script is executable: chmod +x script.sh
  • Environment variables missing — cron runs with a minimal environment; use full paths for everything
  • No output/feedback — redirect both stdout and stderr to a log file with 2>&1
Pro Tip

Use crontab.guru to build and verify cron schedule expressions. It shows you in plain English when your cron job will run, so you don't have to guess the syntax.