Unix Cron & WordPress
Creëer voor elke WordPress-site een cron job for user www-data.
Dit is het commando dat WP Rocket ca. elke 10 minuten uitgevoerd wil hebben via Cron:
wget -q -O - https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Oftewel: Een bepaalde file uit de betreffende installatie wordt aangeroepen, en de output gaat naar /dev/null
.
Syntaxis
Timefields:
Minute Hour Day of month Month Day of week Opmerkingen 0-59 0-23 1-31 1-12 0-6 (0 = Sunday) Mogelijke waardes ------ ---- ------------ ----- ---------------- ----------- 0 16 1,15 * * Do something on day 1 & 15 at 16:00 */10 * * * * Do something every 10 minutes
crontab - Voorbeelden
$ crontab -l no crontab for jeroen
$ crontab -l -u www-data must be privileged to use -u
$ sudo crontab -l -u www-data no crontab for www-data
$ sudo crontab -e -u www-data no crontab for www-data - using an empty one Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/vim.basic 3. /usr/bin/vim.tiny 4. /bin/ed Choose 1-4 [1]: 2 ... interactieve bijwerken cronfile... crontab: installing new crontab
$ sudo crontab -l -u www-data # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be defined through a single line # indicating with different fields when the task will be run # and what command to run for the task # # To define the time you can provide concrete values for # minute (m), hour (h), day of month (dom), month (mon), # and day of week (dow) or use '*' in these fields (for 'any'). # # Notice that tasks will be started based on the cron's system # daemon's notion of time and timezones. # # Output of the crontab jobs (including errors) is sent through # email to the user the crontab file belongs to (unless redirected). # # For example, you can run a backup of all your user accounts # at 5 a.m every week with: # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/ # # For more information see the manual pages of crontab(5) and cron(8) # # m h dom mon dow command */10 * * * * wget -q -O - https://example/wp-cron.php?doing_wp_cron >/dev/null 2>&1
Log
Om te zien of het ook echt werkt:
sudo grep CRON /var/log/syslog
of
sudo grep www-data /var/log/syslog
Zie ook
Bronnen
- https://docs.wp-rocket.me/article/1279-cron-and-wp-rocket
- https://stackoverflow.com/questions/46442933/create-cronjob-ubuntu-for-user-www-data-using-bash#46443063
- https://docs.oracle.com/cd/E19455-01/805-7229/sysrescron-62861/index.html
- https://crontab.guru/every-10-minutes
- https://www.cyberciti.biz/faq/crontab-every-10-min/