Skip to content

CronJob ​

Overview ​

A CronJob makes the server run a command on a schedule, for example running Laravel's scheduler every minute, calling WordPress WP-Cron every 5 minutes or cleaning temporary files every night. You only need to enter the command, choose the user that runs it and pick a schedule.

Create a CronJob ​

  1. Open the server and click the CronJob menu.
  2. Click the CronJob button (plus icon) at the top right to open the Add CronJob dialog.
  3. Enter the command in the editor. Use full paths for every file and folder (e.g. /home/flashpanel/example.com/artisan instead of artisan). Click the Custom Scripts icon in the corner of the editor to insert a command saved in Scripts.
  4. In User, choose the system user that runs the command. Usually pick the user that owns the website (e.g. flashpanel); only choose root when the command needs system administrator rights.
  5. Fill in Description (optional, up to 100 characters) so the job is easy to recognize.
  6. Set the schedule in Cron Expression (see below).
  7. Click Add CronJob.

Set the schedule ​

  • Click Template to pick a preset, such as Every Minute, Every 5 Minutes, Hourly, Daily at Midnight, Weekly (Sunday), Monthly (1st).
  • Or fill in the 5 fields Minute, Hour, Day of month, Month, Day of week yourself. Each field shows the allowed values below it.
  • The box above the fields describes the schedule in plain words. It turns red if the expression is invalid.
  • To run the command once every time the server boots, enter @reboot in the Minute field.

See Cron Job & Cron Expressions Guide for the full cron syntax.

Manage CronJobs ​

The CronJob table shows ID, Description, Cron (hover to see the explanation) and User. Click the arrow at the start of a row, or anywhere on the row, to see the full command.

Buttons in the Action column:

  • Run (triangle icon): run the command right away in a terminal window as the selected user, to test it without waiting for the schedule.
  • View Log: open the last lines of the job log, including the output and error messages of its runs. The log opens in a floating window that you can move, resize or minimize, with the colors written by the program kept. Choose how many Lines to show, turn on Auto refresh to reload every 5 seconds, or click the refresh button to reload once.
  • Edit CronJob: reopen the dialog to make changes, then click Update CronJob.
  • Trash icon: delete the job after confirming.

System-created CronJobs

Some features create CronJobs automatically, such as the Cleanup System schedule ([FlashPanel] Auto Cleanup System). For these, you can only change the schedule and description, not the command or the user.

Examples ​

Laravel scheduler ​

Run Laravel's task scheduler every minute. Replace example.com with your website folder.

  • Command:

    bash
    php /home/flashpanel/example.com/artisan schedule:run
  • User: flashpanel

  • Schedule: Every Minute (* * * * *)

WordPress WP-Cron ​

Call WP-Cron every 5 minutes so WordPress scheduled tasks run on time, even when the site has few visitors.

  • Command:

    bash
    curl -s https://example.com/wp-cron.php?doing_wp_cron > /dev/null
  • User: flashpanel

  • Schedule: Every 5 Minutes (*/5 * * * *)

Delete old website log files ​

Delete .log files older than 14 days in the application's log folder, every day at 1 AM.

  • Command:

    bash
    find /home/flashpanel/example.com/storage/logs -name "*.log" -mtime +14 -delete
  • User: flashpanel

  • Schedule: 0 1 * * *

Commands that need root

System-wide commands, such as updating packages (apt-get upgrade) or deleting files in /var/log, only work with the root user and can break the server if written incorrectly. To clean system logs and caches, use the Cleanup System utility instead of writing your own CronJob. Always click Run to test a command before leaving it to the schedule.

Troubleshooting ​

If a CronJob does not run as expected:

  1. Click View Log to read the error message from the latest run.
  2. Click Run to test the command right away and see the output.
  3. Make sure the command uses full paths. CronJobs do not run inside the website folder, so php artisan schedule:run fails while php /home/flashpanel/example.com/artisan schedule:run works.
  4. Make sure the selected User can read/write the files the command uses.
  5. Hover over the expression in the Cron column to confirm the schedule is what you want.