Cron Job with PHP5 CLI and ISP config - bash

I am working on a project under Symfony2, and a dedicated server.
This server got ISP Config Panel.
I want that my cron runs a php-cli command line, integrated in symfony2 (php app/console config:renewalsession ).
My command in PHP-Symfony works really fine. If I run it manually, it does what I want.
But I am blocked with cron jobs. So I did a sh script, who calls the command.
#!/bin/bash
#!/usr/bin/php5
php /var/www/clients/client1/web1/private/app/console config:renewalsession
I set up the cron job, for working in two minutes, I wait, and nothing happen.
I don't know from where it comes ...
So can someone help me ?
Edit :
I got some more informations. My sh script works fine. Problem was coming from how I filled inputs of the cron.
I have to fill a form with "minutes" "hours" "days of month" "months" "days of week" and my command. My command is good.
So the problem come from the rest of inputs.
I want that the cron runs everyday, one time, at 1h am.
So I have filled form this way :
minutes : 0
hours : 1
days of month : *
months : *
days of week : *
What is wrong with those parameters ?

This will run your script at 1AM every day of the month:
0 1 * * * sh /path/to/script.sh

Related

Hourly cron Job Excuting 60 times

I am trying to send an email hourly using the Task scheduler in (laravel) framwork,
the command I am typing in the kernal.php:
$schedule->command('cron:activeUsers')->hourly()->withoutOverlapping();
than put the following in crontab -e:
cd /testEmail && php artisan schedule:run >> /dev/null 2>&1
but I am getting like 60 or even 100 email instead of one,
I put some logs to see what is happening:
the cron job is excuting and sending email on the first 60 second of the first minute of each hour like the following for example:
12:00:00
12:00:01
12:00:02
12:00:03
12:00:04
12:00:05
.
.
12:00:59
how I can prevent the cron job to be excuted like this ? I want the cron job to be excuted only once each hour.
Am I using the wrong method to send the email?
The schedule:run command is supposed to be called every minute (as fast as CRON allows), like so:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
See https://laravel.com/docs/9.x/scheduling#running-the-scheduler
Then, your schedule() function in app/Console/Kernel.php defines the interval for each of your tasks, so your ->hourly() command should execute at the start of every hour.
If it is executing any faster than that, its likely that you somehow happen to call the scheduler more often than once a minute (multiple CRONs maybe for the same command?). Try a debug statement in the schedule() function in app/Console/Kernel.php to see that it actually executes once a minute.
When you put a debug statement inside your actual command (i.e. 'cron:activeUsers'), then you should see that it runs every hour.
59 * * * *
repeat at [Minutes] [Hour] [Day of Month] [Which Month] [Which Week]
use the above value to do it every 60 minutes, If want to check it, you can also use https://crontab.guru/ to verify what exactly you want.
at 59, it tells to redo it every 59 minutes, plus have mentioned already there about the star astreriks for you to test and check along with the url of resource

Laravel cron/schedule monthly() not running

Laravel 5.8.33
I run 2 schedules, one every 5 minutes and one once a month. The five minues schedule runs perfectly using everyFiveMinutes(). But the monthly schedule monthly() never runs. I also tried monthlyOn(1, '00:15') but still the issue remains.
If I swap out monthly() for everyFiveMinutes() it works no problem.
There are no errors in the log file, it simply doesn't run. Has anybody else had this issue? Is there an alternative request to monthly()?
$logfilename = 'cron_'. now()->format('Y_m_d') . '.txt';
//Push Notification check - RUNS EVERY FIVE MINUTES
$schedule->exec('env -i /usr/local/bin/php72 -f /www/xxxx-xxxx.com/artisan command:pushmessages')->everyFiveMinutes()->appendOutputTo(public_path().'/logs/'.$logfilename);
//End of month stats archive - NEVER RUNS
$schedule->exec('env -i /usr/local/bin/php72 -f /www/xxxx-xxxx.com/artisan command:archivestats')->monthly()->appendOutputTo(public_path().'/logs/'.$logfilename);
I know it's late answer but this could be helpful. it's strange as the syntax is correct and I can think of only 1 reason which is the command itself could you share archivestats command code ?
Here are some steps to follow:
run this command:
$schedule->exec('env -i /usr/local/bin/php72 -f
/www/xxxx-xxxx.com/artisan
command:pushmessages')->monthly()->appendOutputTo(public_path().'/logs/'.$logfilename);
if it works then for sure the problem is in the archivestats command.
create a cron task (from GUI or from the terminal for example but not from laravel) that will run on the server monthly ... checkout this link and this link as well.
if you could share the results of the above steps that will help in detecting what's wrong.
If your first command takes over a minute to run, your second command might never see 00:00 in order to run monthly.
Try changing the order of the jobs so that the monthly task gets opportunity to run at midnight.

Magneto Newsletter mails are not going

I am having Magento 1.9.3 and i am new to Magento.
My newsletter subscription is not working. I have checked all things in magento configuration. Seems its the trouble with cron on server. But with out knowing i do not want to make changes on server. I am using A2 hosting provider, and there is a cron set like this, which runs for every 30 mins.
/bin/cagefs_enter.proxied php /home/lasakico/public_html/cron.php 1>/dev/null 2>/dev/null
I am not sure what is the problem, either its the problem with cron or magento.
I have checked magento configuration->Advanced->System->Cron, where values are stored for Generate Schedules Every : 15. and rest are like 20, 15, 10, 60,600
Please let me know if anything is not clear in the question. I will ans them.
Magento has a script called cron.php which handles all of the timed jobs that your Magento store has to do. In this list is the task of sending out newsletters. You have to set up your server crontab to run this cron.php script at regular intervals (eg 5 minutes).
Once you do this, you should find that your newsletter will be sent out as expected
Open up an SSH session with your server. (If you can’t do this you
are going to have to ask your hosts to do this for you instead).
Browse to the document root of your magento store, the folder with
cron.php in there
enter the command
pwd This command gives you the current full path. Write this down
somewhere
enter the command
which php
This command gives you the path to your PHP binary. Write this down somewhere
enter the command
crontab -e
This opens up your crontab editor which is the system for scheduling
tasks on Linux
hit the [i] key to go into insert mode on the crontab editor (vi
basically)
on a new line paste the following, but replacing the paths with the
paths you got before
*/5 * * * * /path/to/php -f /path/to/cron.php
Hit [esc] then type the command
:wq
This saves the crontab or cntrl + x and Y
Create a newsletter and schedule it to send in 2 minutes time.

Cronjob won't run 80% of the time

I have a raspberrypi setup with emulation station and retropie. I have a cronjob set up so I can send myself an email at 8am everyday written in ruby. This script has worked effectively 100% when I first set it up but ever sice I upgraded my raspberrypi to the newest version of retropie and emulationstation, the cronjob has stopped work 80% of the time.
0 8 * * * ruby /home/pi/Facebook/facebook.rb
Is what it is currently. It worked yesterday.
I've tried these methods as well:
0 8 * * * 'ruby /home/pi/Facebook/facebook.rb'
0 8 * * * /bin/bash ruby /home/pi/Facebook/facebook.rb
0 8 * * * /bin/bash 'ruby /home/pi/Facebook/facebook.rb'
0 8 * * * /bin/bash -l -c 'ruby /home/pi/Facebook/facebook.rb'
I am not sure what the -l and -c is supposed to mean. However this one worked all the time when I had it set up before upgrading. Is the pi skipping the job at 8am or doing another job at that time which causes it to miss it? Or is it my script which may take forever to send the email via ruby to my gmail account?
Usually cron sends a error mail to the owner of the crontab, so check that owner's emails on that machine.
It is most likely a problem with the cron environment. Cron uses its own environment when starting jobs.
It sounds like the cron job is running your script, but your script may be erroring-out or timing out. You might want to add some logging to your script, so you can see where the problem is.

How to automate execution of commands by day and hour on Debian?

So I am a working on a simple home lightning control using Raspberry Pi (and raspbian). I can turn or dim lights by writing commands to a zigbee dongle (through a serial interface) by running a command like:
sudo echo "#1*##*1231#*9#" > /dev/ttyUSB0
One of its main functions is to program "scenes" so you can turn lights on and off at certain hour or day.
So how can I automate a bash command to run lets say monday, tuesday and saturday at 8:55AM every week? Thanks!
Use crontab. Those threads will help you:
how to set cronjob for 2 days?
Crontab Day of the Week syntax
So:
crontab -e # edit crontab file
and then insert
55 8 * * 1,2,6 /usr/local/bin/my_cool_script
In case crontab is not flexible enough for your needs, you can use Ruby Rufus scheduler

Resources