# Cron job setup, which way is better?

**URL:** https://forum.mautic.org/t/cron-job-setup-which-way-is-better/9613
**Category:** General Discussion
**Created:** [October 3, 2017, 2:18pm UTC](https://forum.mautic.org/t/cron-job-setup-which-way-is-better/9613 "2017-10-03T14:18:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![fususu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/fususu/32/215_2.png) [@fususu](https://forum.mautic.org/u/fususu)
#### Post date: [October 3, 2017, 2:18pm UTC](https://forum.mautic.org/t/cron-job-setup-which-way-is-better/9613/1 "2017-10-03T14:18:20Z")

</div>

Hello,  
  
  
  
I’m installing the cron job. I want to send email as often as possible, so I have to setup cron to run every minute. I have two options.

1. Execute all commands at once every minute

Code:

\*/1 \* \* \* \* php /home/mydomain.com/public\_html/app/console mautic:email:send \> /dev/null 2\>&1 \*/1 \* \* \* \* php /home/mydomain.com/public\_html/app/console mautic:campaigns:trigger \> /dev/null 2\>&1 \*/1 \* \* \* \* php /home/mydomain.com/public\_html/app/console mautic:segments:update \> /dev/null 2\>&1 \*/1 \* \* \* \* php /home/mydomain.com/public\_html/app/console mautic:campaigns:rebuild \> /dev/null 2\>&1

  
With this method, the CPU went to the roof 100%, for about 3-5 seconds each time the cron run.  
 ![cach1.jpg](http://sv1.upsieutoc.com/2017/10/03/cach1.jpg)  
  
2. Make a batch script and make the previous command wait for 10 seconds before executing the next

Code:

\*/1 \* \* \* \* /root/mtcron.sh \> /dev/null 2\>&1

  
The mtcron.sh file content:

Code:

#!/bin/bash php /home/mydomain.com/public\_html/app/console mautic:campaigns:trigger \> /dev/null 2\>&1 sleep 10 php /home/mydomain.com/public\_html/app/console mautic:segments:update \> /dev/null 2\>&1 sleep 10 php /home/mydomain.com/public\_html/app/console mautic:campaigns:rebuild \> /dev/null 2\>&1 sleep 10 php /home/mydomain.com/public\_html/app/console mautic:email:send \> /dev/null 2\>&1

  
With this method, the CPU never goes to the roof, but it will peak at around 60-70% for 4 times in a minute.  
 ![cach2.jpg](http://sv1.upsieutoc.com/2017/10/03/cach2.jpg)  
  
Which way is better?

---

<div class="post-metadata">

### Author: ![fususu](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/fususu/32/215_2.png) [@fususu](https://forum.mautic.org/u/fususu)
#### Post date: [October 3, 2017, 2:18pm UTC](https://forum.mautic.org/t/cron-job-setup-which-way-is-better/9613/2 "2017-10-03T14:18:20Z")

</div>

Hello,

I’m installing the cron job. I want to send email as often as possible, so I have to setup cron to run every minute. I have two options.

1. Execute all commands at once every minute

`*/1 * * * * php /home/mydomain.com/public_html/app/console mautic:email:send > /dev/null 2>&1
*/1 * * * * php /home/mydomain.com/public_html/app/console mautic:campaigns:trigger > /dev/null 2>&1
*/1 * * * * php /home/mydomain.com/public_html/app/console mautic:segments:update > /dev/null 2>&1
*/1 * * * * php /home/mydomain.com/public_html/app/console mautic:campaigns:rebuild > /dev/null 2>&1`

With this method, the CPU went to the roof 100%, for about 3-5 seconds each time the cron run.  
 ![](http://sv1.upsieutoc.com/2017/10/03/cach1.jpg)

1. Make a batch script and make the previous command wait for 10 seconds before executing the next

```auto
*/1 * * * * /root/mtcron.sh > /dev/null 2>&1
```

The mtcron.sh file content:

```auto
#!/bin/bash
php /home/mydomain.com/public_html/app/console mautic:campaigns:trigger > /dev/null 2>&1
sleep 10
php /home/mydomain.com/public_html/app/console mautic:segments:update > /dev/null 2>&1
sleep 10
php /home/mydomain.com/public_html/app/console mautic:campaigns:rebuild > /dev/null 2>&1
sleep 10
php /home/mydomain.com/public_html/app/console mautic:email:send > /dev/null 2>&1
```

With this method, the CPU never goes to the roof, but it will peak at around 60-70% for 4 times in a minute.  
 ![](http://sv1.upsieutoc.com/2017/10/03/cach2.jpg)

Which way is better?

---

<div class="post-metadata">

### Author: ![bobinson](https://avatars.discourse-cdn.com/v4/letter/b/67e7ee/32.png) [@bobinson](https://forum.mautic.org/u/bobinson)
#### Post date: [October 3, 2017, 4:44pm UTC](https://forum.mautic.org/t/cron-job-setup-which-way-is-better/9613/3 "2017-10-03T16:44:45Z")

</div>

I feel the second method is better as the CPU spikes and evenly distributed over a period of time as opposed to sharp spikes.

---

<div class="post-metadata">

### Author: ![petertl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/petertl/32/511_2.png) [@petertl](https://forum.mautic.org/u/petertl)
#### Post date: [October 4, 2017, 7:39am UTC](https://forum.mautic.org/t/cron-job-setup-which-way-is-better/9613/4 "2017-10-04T07:39:32Z")

</div>

Please don’t trigger all actions at the same time. If you do, you will likely encounter this: [https://github.com/mautic/mautic/issues/3669](https://github.com/mautic/mautic/issues/3669)
