A cron job is for anything you would otherwise repeat by hand at the same time every day or week: taking a copy of the database, deleting temporary files, importing a price list, sending a summary by e-mail. If you already know how to create one, here are seven concrete uses for a small site on shared hosting. To create one, see cron jobs: what they are for and how to create one.
Seven ideas, most useful first
| 1 |
A database copy every night. A mysqldump into a folder outside public_html, named after the day. It is your insurance against a mistake of yours or a plugin’s. The steps are in automatic backups with cron and mysqldump.
|
|
| 2 |
Clearing out old files. Exports, temporary files and old copies fill the space without anyone noticing. For example, find /home/ACCOUNT/exports -type f -mtime +7 -delete removes whatever is older than seven days. Run it first with -print in place of -delete to see what would go.
|
|
| 4 |
Calling an address on your own site. Many applications ship a file made for this, such as /usr/bin/curl -s "https://asuaempresa.co.mz/cron.php?key=SECRET" >/dev/null 2>&1. Put a key in the address, or anyone can call it.
|
|
How often, and where to see the result
| Job |
A reasonable frequency |
Where you see it ran |
| Database copy |
Once a day, in the small hours. |
The new file in the backup folder. |
| Clearing files |
Once a day or once a week. |
A smaller folder; use >> for a log. |
| WordPress cron |
Every five minutes. |
A scheduled post that goes out on time. |
| Importing data |
When the supplier updates, plus a margin. |
The modification date of the file or table. |
| E-mail report |
Once a day or once a week. |
The e-mail in your inbox. |
|
A cron job spends your account’s resources like a visitor does. Do not schedule anything every minute unless you must: if one run takes longer than the interval they start piling up. The reasoning is in cron jobs.
|
Keep scripts outside public_html, in a folder such as /home/ACCOUNT/scripts. Nobody can open them from a browser, and they stop depending on the site’s address. Add >> /home/ACCOUNT/cron.log 2>&1 to the end of the line for the first weeks, so you have a record of what happened.
|
|
Want a plan with cPanel and scheduled tasks? See the hosting plans.
See the plans
|
Where to see it in your account
Your cron jobs run inside your account, under the same limits as the rest of the site. The Cron Jobs page in cPanel lists what is scheduled and when. To know whether a job ran into a limit, open Resource Usage: it shows CPU, memory, entry processes and I/O against the limits of your account, and when the ceiling was reached. A job that goes past those limits can be slowed down or stopped, so it is better to split long jobs into short parts or, for heavy work, move them to a VPS, which gives you full SSH access. For the exact figures that apply to your account, read them on those screens or ask us.
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from 396,00 MT/mo (3-year plan, with coupon) See plans |