I have a bunch of Behat test scenarios, about 3000, these take about 3h to run, and I have deducated machine to run these, so looking for a command which would trigger this command:
./behat --tags oxi --profile staging --format custom
Every 3h. Is there any way to do this?
I looked at "watch" command but even if I do run it:
watch -n 10800 ./behat...
the watch for some reason is running it every 4294 seconds. Not 10800 which I stated in command. So is there any other way of doing this?
Thank you.
First move the command to it's own script vi /usr/local/bin/dowatch:
#!/bin/bash
./behat --tags oxi --profile staging --format custom
Make it executable
chmod +x /usr/local/bin/dowatch
Cron seems like a good choice for scheduling... in the shell:
crontab -e
Then edit the source to:
* */3 * * * /usr/local/bin/dowatch
Which says any minute (first) every three hours (second) any day of the month (third) any month (fourth) any day of the week (fifth) execute /usr/local/bin/dowatch
Related
I have this in my Kernal.php:
$schedule->call('removeTemporaryFiles')->everyMinute();
When I hit php artisan schedule:run it works like charm. But I also ran:
* * * * * php /var/www/html/archive/artisan schedule:run >> /dev/null 2>&1
But it is not running automatically. I have waited more than a minute but it is still not running. What am I doing wrong?
And where is the main machine cron saved? The one that runs every minute and calls artisan schedule:run?
In order for Schedules to run, you need first to add the cron job to your cron table. Run this command
sudo crontab -e
Then choose your preferred editor.
Then add the below line:
* * * * * php /var/www/html/archive/artisan schedule:run >> /dev/null 2>&1
Finally in your Kernel.php you add the schedule:
$schedule->command(<artisan command>)->everyMinute();
The documentation is perfectly detailing it.
Finding cron jobs:
Depending on how your linux system is set up, you can look in:
- /var/spool/cron/* (user crontabs)
- /etc/crontab (system-wide crontab)
also, many distros have:
- /etc/cron.d/* These configurations have the same syntax as /etc/crontab
- /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, /etc/cron.monthly
These are simply directories that contain executables that are executed hourly, daily, weekly or monthly, per their directory name.
On top of that, you can have at jobs (check /var/spool/at/*), anacron (/etc/anacrontab and /var/spool/anacron/*) and probably others I'm forgetting.
References : https://unix.stackexchange.com/questions/7053/how-can-get-a-list-of-all-scheduled-cron-jobs-on-my-machine
I am having big issues with the cron of Magento 1.9.1 hoping someone can help. I have AOE installed and see not heartbeat.
I have added my cron job
*/5 * * * * /bin/sh /var/sites/p/domain/public_html/cron.sh
But this still does not run, so I decided to try and try and run cron.php, this does nothing. This is my cron for this
*/5 * * * */usr/bin/wget -O /dev/null -o /dev/null http://www.domain.com/cron.php
Based on Magneto 1.8 cron.php I added the following to the cron.php.
$isShellDisabled = true;
Based on this still not working I tried the cron.php in the browser. I get an error in the browser that Printing is disabled by default for security reasons.
So I changed my php.ini to memory_limit = 512M just incase. This is still not working.
The error I get in my reports for this is:
a:5:{i:0;s:59:"Mage registry key "_singleton/cron/observer" already exists";i:1;s:537:"#0 /var/sites/p/domain.co.uk/public_html/app/Mage.php(223): Mage::throwException('Mage registry k...')
#1 /var/sites/p/domain.co.uk/public_html/app/Mage.php(477): Mage::register('_singleton/cron...', false)
#2 /var/sites/p/domain.co.uk/public_html/app/code/core/Mage/Core/Model/App.php(1316): Mage::getSingleton('cron/observer')
#3 /var/sites/p/domain.co.uk/public_html/app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('default', Array)
#4 /var/sites/p/domain.co.uk/public_html/cron.php(74): Mage::dispatchEvent('default')
#5 {main}";s:3:"url";s:9:"/cron.php";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}
Any help would be really great.
Note ** I have change the domain name to DOMAIN due to my site not being suitable for work.
Few simple steps to fix Magento cron issue:
Go to System > Configuration > Advanced > System > Cron (Scheduled Tasks) and set next values:
Generate Schedules Every: 15
Schedule Ahead for: 20
Missed if Not Run Within: 15
History Cleanup Every: 10
Success History Lifetime: 60
Failure History Lifetime: 600
Clear Cache in System > Cache Management
Clear 'cron_schedule' table. You can do it via phpmyadmin or execute next command in SQL console:
TRUNCATE TABLE cron_schedule;
Add next line to cron settings (use absolute paths):
*/5 * * * * /usr/bin/php /absolute/path/on/your/server/to/file/cron.php
Note: in some configurations on webserver (apache/nginx) allowed to execute php scripts. In this case add this line to webserver's user crontab. Example for apache: crontab -u apache -e
Restart cron daemon.
Check table 'cron_schedule', if it's not empty - Magento cron script start working.
Well I've had a different issue. My cron was simply not working, although cron.php was executed properly. Still no output, and no jobs done.
I've checked cron_schedule and noticed that last job there is from 19th of March this year (sic!). So i kept on looking for cause.
Finally I've noticed that that there is process running with my cronjob from 19th of March (sic!).
josh 21350 99.6 0.4 350400 133492 ? R Mar19 241812:21 /usr/bin/php /var/www/mysite/cron.php -mdefault
I've killed the job with: kill -9 21350
And voila! Suddenly newsletter is being sent!
I had no idea why, and how this happened. Now i know i should pay attention to it, so I will.
I just saw that you are using magento 1.9.1.
Run the cron using php instead : /usr/local/bin/php -f /home/cpanel_username/public_html/cron.php
This should resolve http permission problems you might be having when using 'usr/bin/wget -O /dev/null -o /dev/null'
Try that command and let me know if it works for you.
one of my cronjobs send an email daily
35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1
I stopped cron using
sudo service cron stop
when i check the cron status
sudo service cron status
it is cron stop/waiting
the problem is i stopped my crons yesterday , but today also the email was sent again
am i doing this wrong
1.how to stop all cron jobs properly
2.how to view last ran cronjob list .
i tried to get last ran cronob details by
grep cron /var/log/syslog
but it is empty , but when i go to the syslog file i can see the word CRON in some places .
Aug 12 09:10:01 64177 CRON[6388]: (root) CMD (cd /var/www && /usr/bin/php runcronjobs.p......
also when i tries typing
ps -ax|grep cron
5696 pts/3 S+ 0:00 grep --color=auto cron
13011 ? Ss 0:00 cron l
is it possble to run crons after i stopped the cron jobs ??
Thanks in advnace
The proper way to do it is to put every job or every group of jobs in their own 'namespace' / file:
/etc/cron.d/production-job-mail-on-delivery
/etc/cron.d/production-aggregate-account-data
/etc/cron.d/devel-job-mail-on-delivery
/etc/cron.d/system-cleanup-sundy
/etc/cron.d/common-mailings
When you want to stop, you just move those files out of the /etc/cron.d/ folder.
You should not stop the cron service and you shouldn't use crontab / /etc/crontab on a bigger system.
Why?
For example, I have 200 cronjobs on a system. /etc/crontab file gets very messy. Some jobs need to be stopped for a week for example, others need to run permanently. Using cron.d folder this is a very simple task.
Normally you would access your crontab with:
crontab -l (lists cronjobs)
and to edit:
crontab -e
to stop a cronjob temporarily you can usually just comment out the first digit:
# 35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1
to no longer run a cronjob permanently just delete the particular job. crontab usually restarts itself automatically after you edit it. if not trying using:
sudo restart cron
more information: http://man7.org/linux/man-pages/man1/crontab.1.html
The simple way to do it is commenting the cronjob trough a crontab -e:
#35 6 * * * cd $EZPUBLISHROOT && $PHP runcronjobs.php -q 2>&1
Other than that you should configure the time the frequency of the cronjob to run.
To stop processes you can
ps|aux grep runcronjobs
and after you get a list of the processes runing you can just kill a process using its number
kill *number
I'm trying to set up a cronjob script on my server. I've followed this tutorial and I now have a folder "scripts" with "cronjob.php":
<?php
define("_CRONJOB_",true);
require(APPLICATION_PATH . '../public/index.php');
// my executions
?>
In my "index.php" file:
if(!defined('_CRONJOB_') || _CRONJOB_ == false)
{
$application->bootstrap()->run();
}
But how can I set this on my server?
I've done the following as a start: chmod 755 cronjob.php, but what's next?
Use crontab, make sure you have both crontab and php-cli installed.
First edit the cron by doing
$ crontab -e
Then insert something like this
*/10 * * * * /usr/bin/php /path/to/scripts/cronjob.php
This examples does execute the script every 10th minute.
For more on the syntax see https://en.wikipedia.org/wiki/Cron#Predefined_scheduling_definitions
Alternate method for setting Cron job on Linux Server
Step 1: Open Terminal
Step 2: Type
$ sudo crontab -e
Enter System Password
Step 3: Put Cron URL to be executed for every 5 minutes interval
*/5 * * * * curl http://testwebsite.com/hitcronscript
Reference: https://crontab.guru/every-5-minutes
*Note: For test purpose one may set mail or file/Db entry.
Hope it will help developers.
I'm running an Ubuntu 12.10 server as a LAMP stack. I access this through a SSH terminal (as I don't have access to the physical box).
My question is, is there a way to setup ubuntu to automatically execute a script at chosen times. Like to schedule automatic maintenance scripts that have been built in PHP or really any language (possibly Bash Scripts?). I'm sure this has to be possible.
Since I am a bit newer to linux/ubuntu, any help would be appreciated.
EDIT:
This is one solution I found if anybody else stumbles across this...
sudo crontab -e
...
#daily /usr/bin/wget -q -O /var/log/maintenence.txt /var/www/admin/script.php
You can use the crontab in linux.. That wil suit your purpose.
Cron is a daemon that executes scheduled commands
eg:
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * 0,6 /usr/bin/find
Okay for example.. if you need to run the script file /home/krizna/backup.sh every sunday 12 PM .. just issue the below command
sudo crontab -e
and add this line at the end of the file
# Minute Hour Day of Month Month Day of Week Command
00 12 * * 7 /bin/sh /home/krizna/backup.sh