Multiple Cron jobs in one crontab file

Multiple Cron jobs in one crontab file

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Multiple Cron Jobs in One Crontab File

It is entirely possible to schedule multiple cron jobs within a single crontab file, provided that each entry adheres to the standard five-field time specification and includes a valid command. The example you provided demonstrates the correct syntax:

2 * * * * /path/to/mailCronjob mail.php
20 * * * * /path/to/check my application's subscriptions sub.php

When you execute crontab crontab_file and subsequently run crontab -l, seeing both entries confirms that the system has successfully parsed and stored them. The fact that the second job fails only when running automatically, yet works fine manually, points directly to an execution environment issue rather than a syntax error or logic flaw in your scripts.

The most common culprit in this scenario is the missing PATH variable. Cron executes jobs with a significantly stripped-down environment compared to your interactive shell sessions. When you run a command manually in your terminal, it inherits the full system PATH, allowing it to locate executables like php, curl, or git. However, cron daemons typically initialize with a very minimal PATH (often just /usr/bin:/bin).

If either of your scripts relies on external commands that are not located in these default directories, the job will fail silently. For instance, if mail.php calls sendmail or phpmailer without an absolute path, it might succeed if those binaries happen to be in /usr/bin. Conversely, if sub.php attempts to call a utility installed elsewhere, it won't find it.

To resolve this, you should always use absolute paths for your scripts and any external commands within cron entries. Additionally, explicitly defining the PATH variable at the top of your crontab file ensures consistency across all jobs:

PATH=/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin
MAILTO="your-email@example.com"

2 * * * * /full/path/to/mailCronjob mail.php
20 * * * * /full/path/to/check my application's subscriptions sub.php

Another frequent oversight involves the working directory. When a cron job runs, it does so in the user's home directory unless specified otherwise. If your scripts attempt to read configuration files or data relative to the current directory (e.g., ./config/settings.json), they will fail if that directory structure doesn't exist exactly where the cron job expects it. You can force a specific working directory by adding an cd command before invoking your script:

20 * * * * cd /var/www/app && /full/path/to/check my application's subscriptions sub.php

It is also worth noting that cron jobs run as the user associated with the crontab file. Ensure that this user has the necessary read permissions for any files your scripts access and write permissions for any logs or output files they generate. A common mistake is assuming that because a script works in php artisan tinker (which runs as you), it will work in cron (which might run as www-data or another service account).

If you are using Laravel, the framework provides robust tools to handle background tasks without relying on raw cron commands for logic-heavy operations. You can define console commands in your Console/Kernel.php and schedule them using the scheduler facade:

use Illuminate\Console\Scheduling\Schedule;
use App\Console\Commands\SendEmails;
use App\Console\Commands\ValidateSubscriptions;

public function schedule(Schedule $schedule)
{
    // Send emails at minute 2 past every hour
    $schedule->command('emails:send')->hourly();

    // Validate subscriptions at minute 20 past every hour
    $schedule->command('subscriptions:validate')->hourly();
}

This approach leverages Laravel's internal scheduling mechanism, which handles environment variables, working directories, and error logging more gracefully than raw cron entries. However, if you must stick to a standard crontab file for legacy reasons or simplicity, ensuring absolute paths, correct permissions, and an explicit PATH definition will almost certainly resolve the issue where one job works and another fails silently.

Our network