I've setup a command like this:
protected function schedule(Schedule $schedule)
{
$schedule->command('feeds:fetch')->everyFiveMinutes();
}
I've setup a cron job to run php artisan schedule:run
When I run that line on dev's terminal it runs the task OK. On Prod it returns "No scheduled commands are ready to run."
Any way to troubleshoot this?
The fine folks at Larachat (https://larachat.slack.com/) helped me out debug this issue.
The problem was with my crontab. I was setting the crontab to execute the artisan scheduler as follows:
*/1 * * * * php /path/to/artisan schedule:run
(meaning execute every 1st minute of every hour every day.)
When it should be:
* * * * * php /path/to/artisan schedule:run
(meaning execute every minute of every hour every day.)
So, when I manually ran cron on a non-1st minute of every hour, it didn't run at all.
I have found a solution for this problem. Just add the timestamp in the $schedule.
You can change the command name, time and timezone according to your requirements.
$schedule->command('tenam:before')
->dailyAt('22:28')->timezone('Asia/Kolkata');
Related
I have a cron job set to run a python script say script.py, I have set the cron to run it every 6 hours. The issue is that when the script is getting run, it keeps starting the process again and again. The python script has a few sleeps in it. Technically the script runs and exits when run standalone. For some reason I see the cron trying to start the process again and again.
* */6 * * * python3 /path/to/script.py
I have read answers on using locks and pid files, asking this just to understand the behaviour.
I think that your problem is not that your job is getting restarted after terminating, it will be executed every minute. If you enter a ´*´ this stands for every possible value. So when you enter EVERY VALUE for your minutes, your task is getting executed every minute. Instead, you should use:
0 */6 * * * python3 /path/to/script.py
Hope this solves your problem
I just like to ask if anyone here knows how to automatically start a .sh program in Linux on a daily basis.
This is because I have a server running which runs untill a certain point at midnight then stops. I'd like to have a program that can automatically restart it at a certain time every day.
you can automatically run the script by using the cron deamon
First you have to add the command to cron
crontab -e //this will open a file with your default editor
//to this file add your command at last
command syntax:
* * * * * * /home/loc/shell.sh //runs every minuite
ex */45**** /home/loc/shllscript.sh // runs every 45 mins
cron will do what you need to do.
The first line will start your script at 2:30 every day. The second line will stop it at 12:00
30 2 * * * myscript.sh
00 12 * * * killall myscript.sh
you can also refer to "at", which can run jobs at certain time period
I am using a plugin in moodle that requires running cron. I manually run localhost/moodle/admin/cron.php and it worked. So my question is how can I run this script all the time and not manually. I read about C panel but I'm not sure how to use it.
Any advise is appreciated. Thanks in advance.
If you go to your cpanel on your host, then go to the cron options. It should also you how often you want the cron to run and a script to run.
The script is
usr/bin/php /path/to/moodle/admin/cli/cron.php >/dev/null
If you choose to run every 15 minutes then you should see something like this after setting up cron.
*/15 * * * * /usr/bin/php /path/to/moodle/admin/cli/cron.php >/dev/null
http://docs.moodle.org/25/en/Cron
I've recently started a simple project, just to help me learn the BASH scripting language a little better. Anyway, this script is set to alternate/rotate the user's desktop background/wallpaper at a given interval.
Given that this task would most likely be done every 30 minutes to 1 hour, how should I go about doing this. Would 30 minute/1 hour timers be very inefficient? Or, could cronjobs do a better job for me?
Also, how could I get this script to run in the background, so that a terminal window is not always required to be open?
Could you provide some sort of an idea into the syntax, if you can, as well.
This would be a suitable job for cron. cron would take care of invoking the script at regular intervals. You would not then have to be concerned in your script when the script should run and managing a script running in the background.
Running in the background would be extravagent as the script does not need to do much - not much more than change the current desktop setting. Typically the script would only take a small fraction of a second to complete the task.
cron entries have six fields-:
mins hours day month day-of-week path_to_command
0-59 0-23 1-31 1-12 0-6 command
days of the week start on Sunday. 0=Sunday, 1=Monday etc.
cron entry to run the script every hour for all days and months-:
0 * * * * /path/change_wallpaper.sh
to list your current cron jobs, type
crontab -l
Edit your cron jobs and add the new cron entry-:
crontab -e
Check the new setting is in place -:
crontab -l
I would personally run the script using following crontab:
0 * * * * $HOME/changewallpaper.sh
which you can install as a user with this command
crontab -e
Other solutions include running daemon script from file ~/.xprofile
For more information please refer to
man crontab
man 5 crontab
Also check out this project Variety.
Also, how could I get this script to run in the background, so that a terminal window is not always required to be open?
That would be a daemon. And there's no need to write your own. It's a bit tedious in bash if you want pidfile, start|stop|restart etc. Just add a new cronjob which'll execute your script every n minute or something.
Edit your cronjobs
crontab -e
Execute script every 30 min: (not the same as 30, which would do it every hh:30!)
*/30 * * * * /path/to/your/script
Restart cron. How depends on distro, here's Ubuntu:
service cron restart
List cronjobs:
crontab -l
In my hosting i have a section for cron job like this:
(source: site-helper.com)
The PHP script is called "croned.php", which I want it to run every 10 minutes.
What I will fill in every field?
I tried but it didn't work.
Note: the full path to the script is: /home/axelzd/domains/hellodom.com/public_html/croned.php
Put */10 in the minutes whilst putting * in all other fields.
Usually you can use commas to separate the cron minutes/hours etc. - 0,10,20,30,40,50 in your minute field (but I can't guarantee your admin will take it - I know Plesk does) and * in all others . The command is more tricky, but something like this should do /usr/bin/wget -q -t 5 --delete-after URL_TO_YOUR_CRON or php PATH_TO_YOUR_PHP_FILE_ON_THE_SERVER
try this
*/10 * * * * <command_to_be_invoked>