Cron Jobs
Cron Jobs
If you have ever wished something on your server would just happen automatically — cleaning up old files, running a maintenance script, rotating logs — cron jobs are the answer. Instead of logging in manually or relying on WordPress to handle system-level work, you set a schedule once and FlyWP handles the rest.
A cron job (named after the Unix time-based job scheduler) is a command that your server runs automatically at intervals you define — every hour, once a day, every Sunday at 3 AM, or any other pattern. You define the command and the schedule; the server takes care of the rest.
Overview
The Crons tab on your server’s detail page shows all server-level cron jobs you have configured. If no cron jobs have been added yet, you will see an empty state message: “No cron jobs found.”
Adding a Cron Job
- Navigate to your server’s detail page and click the Crons tab.
- Click the Add Cron button.
- Enter the command you want to run (e.g.,
/usr/bin/find /tmp -type f -mtime +7 -delete). - Set the schedule using cron syntax or a preset interval.
- Click Save.
FlyWP registers the cron job on your server, and it will begin running at the next scheduled time.
Common Use Cases
| Task | Example Command | Suggested Schedule |
|---|---|---|
| Clean up temp files | find /tmp -type f -mtime +7 -delete | Daily |
| Restart a service | docker restart nginx-proxy | Weekly |
| Run a custom script | /home/fly/scripts/backup-cleanup.sh | Daily |
| Clear application logs | truncate -s 0 /var/log/app/*.log | Weekly |
Cron Schedule Syntax
Cron schedules use five fields representing minute, hour, day of month, month, and day of week. Each field accepts a number, a wildcard (* means “every”), or a range.
* * * * *| | | | || | | | +-- Day of week (0-7, where 0 and 7 are Sunday)| | | +---- Month (1-12)| | +------ Day of month (1-31)| +-------- Hour (0-23)+---------- Minute (0-59)Common examples:
| Schedule | Cron Expression |
|---|---|
| Every minute | * * * * * |
| Every hour | 0 * * * * |
| Every day at midnight | 0 0 * * * |
| Every Sunday at 3:00 AM | 0 3 * * 0 |
| Every weekday at 9:00 AM | 0 9 * * 1-5 |
Managing Cron Jobs
Each cron job in the list gives you two actions:
- Edit — update the command or change the schedule at any time.
- Delete — remove the cron job entirely from the server.
Best Practices
- Test your commands manually via SSH (Secure Shell, a way to connect to your server from a terminal) before scheduling them, to confirm they work as expected before automating.
- Use absolute paths in your commands (e.g.,
/usr/bin/findinstead of justfind) to avoid PATH issues — the environment that runs cron jobs does not always have the same settings as your interactive shell. - Stagger schedules — avoid scheduling multiple resource-intensive tasks at the same time to prevent overloading your server.
- Monitor your server resources on the Status tab after adding new cron jobs to confirm they are not causing unexpected load.