I have the following cron tasks:
/etc/cron.d/mongo
/etc/cron.d/elastic
These cron jobs only executes scripts located here:
/etc/script/mongo
/etc/script/elastic
These tasks execute every 30 minuts, that's the following cron format:
0,30 * * * *
I don't know why but these tasks aren't executing all times. In 2 hours, for example, they only execute 2-3 times and not 4. These tasks are performing backups, I need to be sure that they execute every 30 minuts.
Why this is happening?
PD: If i execute crontab -e the file is empty, this may cause any problem?
Related
In my docker container, I have multiple cron jobs that need to be ran, with each doing a different thing:
Some cron jobs will import a module
Some cron jobs will activate the imported module
Finally, some cron jobs will do a cleanup
This is the order in which they should run.
Currently, cron is not a running process in my container however, including the following in my entrypoint script has it running in the foreground:
#!/bin/bash
cron -n -s -m off
With this included, it does run the cron jobs. However, a key point is that each set of cron jobs (import, activate, cleanup) uses one of three bash scripts to perform their tasks. So, for example, the cron jobs that activate a module will have the following format:
MAILTO=""
* * * * * root /tmp/moduleActivation.sh <module> <version>
Each activation cron job will use a bash script that takes in two parameters and the bash script will activate it as so. The way these scripts are set up, only one instance can be running at any one time.
With my current setup, it will attempt to run each cron job at the same time, which is not my desired result as multiple instances of the activation script will attempt to run at the same time, which can't happen.
I am quite new to cron - how can I prevent this from happening and have the cron jobs run in the desired order? Will a crontab file take precedence in some way if I was to include one?
I wan to create cron job that runs a shell script every minute I've tried editing contrab -e with:
1 * * * * sh ~/test.sh
to no avail
I recommend using: https://crontab.guru/
This is a really insightful way to create and understand cron jobs.
This should trigger every minute. However, when a cron runs it can run as a different user and that script location might be different. Adding a log file might help you track down what is going on.
* * * * * /bin/sh /home/user/test.sh >> /var/log/myjob.log 2>&1
In my Laravel scheduler I have many lines like the following
$schedule->command('commandname01')->everyMinute();
$schedule->command('commandname02')->everyMinute();
$schedule->command('commandname03')->everyMinute();
I have noticed that some command e.g. commandname02 is not running anymore
but commandname01 and commandname03 are running.
How could I restore the full commands execution?
Note: if i log into my container and run
php artisan commandname02
It will work fine.
Suspects:
Is it possible that Laravel scheduler stops executing one of the commands if it goes repeatedly on error?
Is it possible that, if commandname01 takes too long, commandname02 will be skipped at same minute execution?
Any other idea?
"Is it possible that, if commandname01 takes too long, commandname02 will be skipped at same minute execution?"
Yes and the reason is that command are not executed in parallel (multithread is not natively available in PHP) but sequentially within scheduler
So if commandname01 takes more than 60" for exec. commandname02 execution will be skipped in the same minute.
Resource: Laravel : Task Scheduling [ In Parallel ]
Solution I adopted and recommend, as provided in link above, it's to implement parallel task leveraging on crontab.
Launch batches to be run in parallel like:
* * * * * php /var/www/artisan batch01 >> /var/log/laravel-scheduler.log
* * * * * php /var/www/artisan batch02 >> /var/log/laravel-scheduler.log
And in batchNN commands just call your commands that can be run sequentially
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?
I am facing a problem with the scripts which i am using in my code, my cronjob runs every 5 mins but the scripts which it is running some time takes more time and i want my cronjob to wait for those files to finish its processing and then execute in the earliest interval is it possible?
Please see below example. Kindly propose me a solution. TIA.
I am running a cronjob for e.g.:
*/5 * * * * /home/Sti/New_Int/fetch_My_Data.sh
This job is invoking below scripts and few details about what each script is doing
fetch_Some_Data.sh --> This script is just moving few files from one location to another so that the only required files can be processed.
tran.sh --> This script opens a for loop and for each file it will open a DB connection by invoking PostP.sh script and for processing it has a sleep time of 60 seconds.
PostP.sh --> This is a script which creates a DB connection and terminates it for each file which is being processed in point 2.
So can you provide me a solution so that if the files are not processed in point 2 the cronjob won't run till then
I usually use a temporary file in such cases to indicate a running instance, and till that file exists all other instances simply exit or Error.
Add this logic to your shell script before doing anything else:
if exists file
then
exit
end if
else
touch empty file
end else