How Can I run a Command after another Command in Laravel - laravel

I have many Command class and they are running in background in my Laravel project.
I have a scenario and I want to run one of the after another one.
$schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
$schedule->command('mycommand:two')->cron("*/40 * * * *")->withoutOverlapping();
they are running every 40 minutes. but I want to run Command two 10 minutes after Command first.
How can I do that?

If you just want to start command 10 minutes after the first command, you have to set properly cron command. So for your example it would be:
$schedule->command('mycommand:first')->cron("*/40 * * * *")->withoutOverlapping();
$schedule->command('mycommand:two')->cron("*/50 * * * *")->withoutOverlapping();
If you want to learn more about those cron settings you can try something like crontab.guru
If you want to run mycommand:two 10 minutes after mycommand:first finished, you have to probably edit mycommand:first to set some timeout and execution of mycommand:second at the end of the command.

Related

Crontab not running properly on MacOS

I have set a crontab for a PHP script, which executes itself with no issues. My question is about the crontab; currently, I have this:
30,* 11 * * * php /Users/username/script.php >>/Users/username/script.log 2>/Users/username/script-error.log
With this crontab, I would expect the execution of the script every minute within 11:30 and 11:59.
Instead, the script is being executed every minute within 11:00 and 11:59.
How can I set a crontab that allows me to run the script every minute within 11:30 an 11:59?
Thanks
The comma in 30,* acts as a separator for two values: the first value 30 and the second value *. As the second value (*) matches every minute, the script is executed every minute.
What you want is a range, which you could specify with 30-59:
30-59 11 * * * php /Users/username/script.php >>/Users/username/script.log 2>/Users/username/script-error.log

How to run Bash Script in Crontab on Raspbian?

I have gone through all sorts of answers and replies up and down the Internet and nothing to seem to work for me. I want to simply run a bash script every minute using CRONTAB on Raspberry PI on Raspbian.
I have a script called autocon.sh and I simply entered into crontab as follows:
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
...
1 * * * * root bash /home/pi/autocon.sh
BUT IT WON'T RUN.
What am I doing wrong?
I'm not sure where the 'root' part comes from, but I'm guessing you're wanting to run the script as root? If so, you need to put an entry into the root crontab, do so by running:
sudo crontab -e
This will open up the root user crontab for editing, anything run from said location will run with root priveleges.
Insert the following line:
* * * * * bash /home/pi/autocon.sh
That should do it :) The 1 in your script actually means 'run at 1 minute past the hour' and thus in your case, 1 minute past every hour - easy mistake! Replacing it with a * means every minute.
The syntax is:
minute - hour - day of month - month - day of week - command
Additionally, if you make your script executable, like so:
sudo chmod +x /home/pi/autocon.sh
You can omit the 'bash' command, and simply use:
* * * * * /home/pi/autocon.sh
And unless you're using the two lines at the top for something in particular, you can omit those too.
For clarity, Barmar's comment on my original post:
In per-user crontab files you don't put the username. But in
/etc/crontab you do.
To run a cronjob every minute, all the values must be stars. Your cronjob is set to run at 1 minute past the hour every hour.
It should be:
* * * * * root bash /home/pi/autocon.sh

Cron doesn't work in Magento1.7

I use Magento for my shopping, and I want to give all logged-in users have 3% discount for all products, so I wrote a rule, but it only worked for two days and after two days I had to re-apply it again, my Cron setting in Magento admin is:
Generate Schedules Every: 60
Schedule Ahead for:10
Missed if Not Run Within:60
History Cleanup Every:120
Success History Lifetime:120
Failure History Lifetime:120
To solve this problem, I wrote a Cron job in DirectAdmin panel to call cron.sh file in root of Magento (cron.sh is a shell script file that call cron.php), but it did not work properly, please guide me to solve this problem.
Cron job setting in Directadmin panel is:
0 0 * * * /usr/local/bin/php /home/noorantel/domains/nooran.com/public_html/shopping/cron.sh >> /home/noorantel/domains/nooran.com/public_html/shopping/var/logfile.txt
So firstly the Magento cron should run with the following regularity.
*/5 * * * *
This will mean that it will run every 5 mins.
Secondly you seem to mix up what type the file is either you need to run the php version or the bash version but what you seem to be doing is trying to run the bash version with php. Try the following.
*/5 * * * * /bin/sh /absolute/path/to/magento/cron.sh
Or
*/5 * * * * /usr/local/bin/php /absolute/path/to/magento/cron.php

Status of cron job

I have written a cron job as follows:
$crontab -e
Then it opened a file where i wrote
5 * * * * USERNAME PATH-TO-SHELLSCRIPT
How would i come to know that my job has been executed?
Do something with the script? Edit a file and add timestamp for example to see if its ok :)
You can use a log file. Create a file under your home directory, e.g., "/home/user/.cronlog/script1", and output script execution time and status messages with timestamps. You can then check the logs to see script history. To test your script first execute it every minute. Then change the crontab entry to the actual period.
Also make sure you understand the time parameters so you know when to expect it to work :)
I use crontab for a 5 min interval cron like this: */5 * * * *
http://en.wikipedia.org/wiki/Cron

crontab is not running my script

I'm new to cron jobs. I read a post on how to write a cron job with crontab.
So my crontab looks like this:
1 * * * * /Users/apple/Desktop/wget/down.sh
which basically means that every minute i want to execute the script :down.sh. Now the script runs
fine manually. The script is a simple program that downloads a PDF from the internet:
#!/bin/bash
wget -U Mozilla -t 1 -nd -A pdf "http://www.fi.usj.edu.lb/images/stories/HoraireS08/3eli.pdf" -e robots=off;
I don't know why it's not running every minute once the terminal tells me that he's installing the new crontab.
Can somebody help me please?
Solution:
Thank you all for your help, the syntax as mcalex said should be
* */1 * * * path/to/script
if you want it to be executed every hour.
The cron job was working normally.However my mistake was simply writing permissions, in fact while executing the wget command, it's supposed to write the pdf file in the current workind directory which is a system directory in case of the cron tab. so i solved my problem simply by navigating to the Desktop directory before executing the wget command like so:
cd /Users/apple/Desktop/wget
and then do whatever i want to do.
PS: i should include the full path of the wget command too.
Thank you all for you help again:)
When you put 1 in the first column, it will run on the first minute (of every hour). In order to get it to run in every minute of every hour, you need to set the minute column as */1
So your line should read:
*/1 * * * * /Users/apple/Desktop/wget/down.sh
supporting links:
job every minute: https://bbs.archlinux.org/viewtopic.php?id=59180
job every 5 minutes: http://www.thegeekstuff.com/2011/07/cron-every-5-minutes/
1 * * * * /Users/apple/Destop/wget/down.sh
From this entry script will never run on every minute because it will run on first minute of every hour.
Make this change to your crontab file to run this script every min.
"* * * * * /Users/apple/Destop/wget/down.sh"
Do you have a typo? It looks like you might have mis-typed Desktop?
Another thing to do is to redirect the output of running the script to a file so you can see what's going on like this:
1 * * * * /Users/apple/Destop/wget/down.sh >> /tmp/cron.out
and then check out the file to see what's going on.
Did cron send you some email detailing what went wrong?
Does the script under that path exist?
Note that cron uses /bin/sh to execute commands.
Did you set a proper PATH in your script? wget may not be in the default PATH or there may be no PATH at all. Try using /path/to/wget in the script.
Note that downloading the same PDF file once a minute is probably a silly idea, though...
If your cronjob is writing things to disk then be careful that system preference "Put hard disk to sleep when possible" is unchecked.
This was preventing my cronjob backup tasks to execute.

Resources