Crontab task scheduled every hour stops running from 11am to 12am - bash

I have a rather weird issue. My aim is to use ffmpeg to grab a screenshot from a home CCTV cameras rtsp stream every hour. I want to do this in order to make a timelapse. However everyday from 11am to 12am (the next day) there are no snapshots saved.
On an always on Debian machine, this is the shell script I have that crontab calls:
dt=$(date +"%d%m%2y%I%M%S")
ffmpeg -rtsp_transport tcp -i "rtsp://IP:554/..." -frames 1 /user/snapshots/ch1/$dt.jpg
Running it by itself works fine and saves a jpg snapshot successfully to the right folders.
In crontab -e I have the following line:
0 * * * * /bin/sh //user/snap.sh
Thanks.

%I is the hour on a 12-hour clock (intended to be used with %p), so your afternoon files are overwriting the morning ones. Use %H instead.

You should add something like
0 11-0 * * * /bin/sh //user/snap.sh
Mean task will start every minute 0 from every hour from 11AM to 12AM

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.

Scheduling a script

I want to schedule a script at different timings on different day but with a single crontab entry. e.g I want to schedule a script like below:
it should run at
30 8-5 * * 1-4 script.sh on mon-thu
and same should run at:
30 11-5 * * 5-6 script.sh on Fri,Sat.
Please suggest how to schedule this in one crontab entry.
You can't.
Just being curious: Is there any advantage in having it into one line, except that it saves you typing "script.sh" twice?

Godaddy Cron Job Running every seconds in cpanel

I need to load a file every seconds, which means, there is not a determinate time of the day.
I am using cPanel to run the CronJob and the task (the wget) is already working fine and I am just having trouble with the time schedules.
I have tried:
Minute Hour Day Month Weekday
*/1 * * * *
running every minute:
Minute Hour Day Month Weekday
* * * * *
it seems a bit odd why you run it every second. Cron job cannot be used to schedule a job in seconds interval. i.e You cannot schedule a cron job to run every 1 seconds. The alternative is to write a shell script that uses ‘sleep 1′ command in it.
$ cat every-1-second.sh
#!/bin/bash
while true
do
/home/ramesh/backup.sh
sleep 1
done

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