I have a cron file that contain this
# 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
MAILTO="myemail#gmail.com"
* * * * * php /home/forge/biossantibodies/artisan products:exportdiff --env=development
* * * * * php /home/forge/biossantibodies/artisan images:exportdiff --env=development
* * * * * php /home/forge/biossantibodies/artisan publications:exportdiff --env=development
* * * * * mailx -s "CronJob is run successfully" ben#gmail.com
I want it to send email to me after the cron job successfully ran.
I've tried:
MAILTO="myemail#gmail.com"
and:
* * * * * mailx -s "CronJob is run successfully" myemail#gmail.com
And I never received any emails, I looked in the spam folder as well, but I noticed the task between them work.
How would one go about configuring this?
Related
Trying to set up a cron on azure devops pipeline but I am getting this error message. I looked at the documentation but not sure what is not in line with the doc. Could someone let me know what is wrong with the my cron syntax? Thank you.
Error while validating cron input. Improperly formed cron syntax: '0 21 * * 1-7'.
Here is the entire yml file.
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- master
schedules:
- cron: "0 21 * * 1-7"
displayName: "pipeline cron test"
branches:
include:
- master
always: true
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: Run a one-line script, changed
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
echo more info
displayName: 'Run a multi-line script'
Here's the relevant part of the doc.
Building Cron Syntax
Each cron syntax consists of 5 values separated by Space character:
1
2
3
4
5
6
mm HH DD MM DW
\ \ \ \ \__ Days of week
\ \ \ \____ Months
\ \ \______ Days
\ \________ Hours
\__________ Minutes
We can use following table to create understand syntax:
Syntax Meaning Accepted Values
mm Minutes 0 to 59
DD Hours 0 to 23
MM Months 1 through 12, full English names, first three letters of English names
DW Days of the Week 0 through 6 (starting with Sunday), full English names, first three letters of English names
Values can be provided in following formats:
Format Example Description
Wildcard * Matches all values for this field
Single value 5 Specifies a single value for this field
Comma delimited 3,5,6 Specifies multiple values for this field. Multiple formats can be combined, like 1,3-6
Ranges 1-3 The inclusive range of values for this field
Intervals */4 or 1-5/2 Intervals to match for this field, such as every 4th value or the range 1-5 with a step interval of 2
You should specify your CRON syntax like the following: "0 21 * * *" or "0 21 * * 0-6", if you want to trigger it for all days of the week.
Days of week: 0 through 6 (starting with Sunday), full English names,
first three letters of English names
Little help or guidance. Server is CentOS 7 - with WHM/CPanel installed.
Command:
$(which php) $(which wp) core update --require=/opt/wp-cli-pre.php --path=/home/USER/public_html/
The contents of /opt/wp-cli-pre.php
<?php
if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'r'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'w'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'w'));
Works as expected from the command line, but if from cron job, I get:
PHP Warning: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in phar:///usr/local/bin/wp/vendor/wp-cli/wp-cli/php/utils.php on line 1057
output of "which php"
/usr/local/bin/php
output of "which wp"
/usr/local/bin/wp
I have installed the latest WP-CLI from https://wp-cli.org/
At long last, I have found the solution.
When the CRON runs a PHP script like this: */5 * * * * php /path/to/script.php
The SAPI name is: cgi-fcgi (on a WHM/CPanel install on CentOS)
It cannot find the CLI version setup by CPanel at /usr/local/bin/php as the $PATH var is just: /usr/bin:/bin
So, the solution is to not depend on the system environment to determine the PHP you want. But to set that directly.
Like this: */5 * * * * /usr/local/bin/php /path/to/script.php
It was always my assumption that if a CRON was setup in ROOT's crontab, it would inherit ROOT's environment. This apparently is not the case.
You should take a look at the following post.
https://forums.cpanel.net/threads/users-cannot-use-wp-cli-in-cron.643293/
I'm trying to create a Scheduler in Laravel 5.8 on my localhost, but it only runs when I use the following command.
php /opt/lampp/htdocs/my_project/artisan schedule:run >> /dev/null 2>&1
php artisan schedule:run
and not runs every minute as i defined
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$good = new Grocery();
$good->name = 'good';
$good->type = 'type';
$good->price = '222';
$good->save();
})->everyMinute();
}
Data is stored in the database, but I should run the command every time.
Nothing is unique in the database.
Your schedule:run needs to be added to your cronjob.
This can be done by typing crontab -e. Once done you should enter the command to be executed every minute:
* * * * * php /opt/lampp/htdocs/my_project/artisan schedule:run >> /dev/null 2>&1
This will set the command to run every minute. Your application is then responsible for seeing if your scheduled command should run.
To set the magento cron we need to add following commands in crontab file on server.
*/10 * * * <path to php binary> <magento install dir>/bin/magento cron:run
*/10* * * * <path to php binary> <magento install dir>/update/cron.php
*/10 * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run
and we can create the custom cron with crontab.xml
<group id="default">
<job name="custom_cronjob" instance="Magento\SampleMinimal\Cron\Test" method="execute">
<schedule>*/5 * * *</schedule>
</job>
</group>
As you can see default magento cron is set for every 10 minutes and magento custom cron is set every 5 minutes.
So my question is custom cron will execute in every 15 minutes or will it execute in every 5 minutes?
You must to install magento crontab by command:
php bin/magento cron:install
In magento 2, cron runs every minute. After install, you will see:
* * * * * /usr/bin/php7.0 /var/www/html/your_project/bin/magento cron:run 2>&1 | grep -v "Ran jobs by schedule" >> /var/www/html/your_project/var/log/magento.cron.log
* * * * * /usr/bin/php7.0 /var/www/html/your_project/update/cron.php >> /var/www/html/your_project/var/log/update.cron.log
* * * * * /usr/bin/php7.0 /var/www/html/your_project/bin/magento setup:cron:run >> /var/www/html/your_project/var/log/setup.cron.log
I have installed Magento 2 using the instructions in the development documentation.
Everything works fine except for the cron jobs that the admin system continually says are not working.
I followed the development docs and added the following lines into my crontabs file.
*/1 * * * * php -c /etc/php5/cli/apache2 /var/www/html/magento2/bin/magento cron:run
*/1 * * * * php -c /etc/php5/cli/apache2 /var/www/html/magento2/update/cron.php
*/1 * * * * php -c /etc/php5/cli/apache2 /var/www/html/magento2/bin/magento setup:cron:run
I have manually run the first and third command and they run without error. The second line I am having problems with. /var/www/html/magento2/update/cron.php does not exist. In fact the update directory does not exist.
Where does the update directory come from, and why don't I have it?
update/cron.php file is in the magento2-community-edition package:
https://github.com/magento/magento2-community-edition/blob/2.0.0/update/cron.php