Multiple cronjob emails - bash

I have 3 jobs in my crontab. I want to recieve emails if only 1 of them fails and not for other two. Is there any way to restric emails to one type of cronjob?

Redirect the output of the two you don't care about to /dev/null if you don't ever want to see the output or to some file if you do.

Your cron likely supports this:
# This job produces mail.
* * * * * echo Hello
# These jobs do not.
MAILTO=
* * * * * echo Foo
* * * * * echo Bar

Related

Cron with wget and flock

I run a php function through laravel controller to process some data from database A and insert it to database B.
public function process_data()
{
$selectA = DB::connection('mysql')->select('select * from A where processed is null');
foreach ($selectA as $data) {
// process code here
$insertB = DB::connection('mysql')->insert('insert into B .... ');
$updateA = DB::connection('mysql')->update('update A set processed = 1 where id = ?', [$data->id]);
}
}
I thought this cron will execute the function once every minute and flock would prevent multiple executions but I found out that there are duplicated entries in database B.
What's wrong with my cron command below?
* * * * * /usr/bin/flock -w 0 /home/ubuntu/cron1.lock wget -O - http://mywebsite.com/process_data &> /dev/null

laravel migration error while creating new one

i tried creating new migration and in my migration file i got the following text
/**
* Gets the first element of `array`.
*
* #static
* #memberOf _
* #since 0.1.0
* #alias first
* #category Array
* #param {Array} array The array to query.
* #returns {*} Returns the first element of `array`.
* #example
*
* _.head([1, 2, 3]);
* // => 1
*
* _.head([]);
* // => undefined
*/
function head(array) {
return (array && array.length) ? array[0] : undefined;
}
module.exports = head;
instead of the normal migration code,
i tried installing the composer , composer dump-autoload
tried clearing cache
but still no luck , it was not like this earlier as i have created many migrations and they were working fine but suddenly it gave me this error,
any idea what is causing this error

How to cronjob task schedule every 40minutes?

How to run 1 job every 40 minutes or 45 minutes in laravel. I have read the laravel documentation with the cron('') function that only performs the correct action for the time specified in cron(''), it does not have to be repetitive after a while.
You can do it by creating 3 crons in the Scheduler:
...->cron('00,45 */3 * * *');
...->cron('30 1-22/3 * * *');
...->cron('15 2-23/3 * * *');
Adapted from: https://www.linuxquestions.org/questions/linux-enterprise-47/cron-every-45-minutes-4175501255/page2.html for laravel

Laravel : Task Scheduling [ In Parallel ]

I have multiple tasks that need to be done every hour or two. All of them have been scheduled via Laravel using below comamnds as cron jobs
$schedule->command('email:notifications1')
->cron('15 * * * * *');
$schedule->command('email:notifications2')
->cron('15 * * * * *');
$schedule->command('email:notifications3')
->cron('15 * * * * *');
Issue:
All of the above tasks are pretty time consuming & it seems from the results that these tasks are not running in parallel. And each tasks runs after the previous has ended.
Requirment
How can i run them in parallel? I want all tasks to be executed (in parallel) as soon as the clock tick the specified time.
Laravel Version 5
You can easily have multiple parallel commands running if you add runInBackground() to the chain.
Like this:
$schedule->command('email:notifications1')
->cron('15 * * * * *')->runInBackground();
$schedule->command('email:notifications2')
->cron('15 * * * * *')->runInBackground();
$schedule->command('email:notifications3')
->cron('15 * * * * *')->runInBackground();
This creates a new process in the background so the Scheduler doesn't have to wait until the command executes. This doesn't even interfere with the withoutOverlapping() method because that works with mutex files.
Now you also have the benefit of having your commands in version control.
The Laravel scheduler can only run one command at a time because of the limitations of PHP.
You could, however, add the cronjobs directly in your crontab file, this way, they will be executed in parallel in separate processes.
15 * * * * * php /path/to/artisan email:notifications1
15 * * * * * php /path/to/artisan email:notifications2
15 * * * * * php /path/to/artisan email:notifications3
Another way to fix this is to let the jobs start at another time. Because a new php process is started every minute by the cron job, these do not affect each other.
For example:
$schedule->command('email:notifications1')
->cron('5 * * * * *');
$schedule->command('email:notifications2')
->cron('10 * * * * *');
$schedule->command('email:notifications3')
->cron('15 * * * * *');

Can I read JavaScript alert box with WatiN?

I want to use WatiN to verify the error message in a JavaScript alert box. Is this possible? Thanks.
see Trev's Blog and here as well.
using(IE ie = new IE("http://hostname/pagename.htm"))
{
AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
using (new UseDialogOnce(ie.DialogWatcher, alertDialogHandler ))
{
/*************************************
* -- alert -- *
* *
* must use the "NoWait" to allow *
* the code to goto the next line *
* *
*************************************/
alertDialogHandler.WaitUntilExists();
alertDialogHandler.OKButton.Click();
ie.WaitForComplete();
}
}

Resources