# Cron Job automatic execution is not wokring

**URL:** https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155
**Category:** Programmierung
**Created:** [4. Oktober 2019 um 13:38 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155 "2019-10-04T13:38:07Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)
#### Post date: [4. Oktober 2019 um 13:38 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/1 "2019-10-04T13:38:07Z")

</div>

I would like run cron job every 30 minutes to check items in the warehouse. We will update stock based on that. When I check by CLI tool

```
sw:cron:run ExampleStockManagerCron

```

. This is working as expected but the interval is not working. Is there any issue with any settings I need.

**A plugin Root file:**

```
addCron();
    }

    /**
     * Uninstall Plugin
     * 
     * Drop a table when plugin uninstall
     */
    public function uninstall(UninstallContext $context): void
    {
       $this->removeCron();
    }

    public function addCron()
    {
        $connection = $this->container->get('dbal_connection');
        $connection->insert(
            's_crontab',
            [
                'name' => 'ExampleStockManagerCron',
                'action' => 'ExampleStockManagerCron',
                'next' => new \DateTime(),
                'start' => null,
                '`interval`' => '100',
                'active' => 1,
                'end' => new \DateTime(),
                'pluginID' => null
            ],
            [
                'next' => 'datetime',
                'end' => 'datetime',
            ]
        );
    }
    public function removeCron()
    {
        $this->container->get('dbal_connection')->executeQuery('DELETE FROM s_crontab WHERE `name` = ?', [
            'ExampleStockManagerCron'
        ]);
return;
    }

   
}

?>

```

**An XML for Cron Register:**

```
        StockManagerCron
        Shopware_CronJob_ExampleStockManagerCron
        true
        300
        true

```

**A Subscriber Class**

&nbsp;

```
 'ExampleStockManagerCron'
           
        ];

    } 

    /**
     * APIStockManagerCron() this will update stock based on API
     */
    public function ExampleStockManagerCron(\Shopware_Components_Cron_CronJob $job)
    {
               
       $responseMsg = 'Product id '.$value['ordernumber'].' updated with QTY '.$goodsQTY;
       $sql = "INSERT INTO `s_plugin_SwagAPI_log` (`id`, `response_desc`) VALUES (NULL, '$responseMsg')";            
       Shopware()->Db()->query($sql);       
        
    }
    
  
}

```

&nbsp;

---

<div class="post-metadata">

### Author: ![sacrofano](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@sacrofano](https://forum.shopware.com/u/sacrofano)
#### Post date: [4. Oktober 2019 um 14:33 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/2 "2019-10-04T14:33:06Z")

</div>

Hello,  
you or your hoster must set up a regular job outside of Shopware that triggers the jobs within Shopware.

See section “Cronjob set up” [Shopware 5 - Settings - System: Cronjobs](https://docs.shopware.com/en/shopware-5-en/settings/system-cronjobs)

&nbsp;

---

<div class="post-metadata">

### Author: ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)
#### Post date: [7. Oktober 2019 um 06:37 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/3 "2019-10-07T06:37:44Z")

</div>

My cron inside plugin folder. How Should I call&nbsp;&nbsp;in :&nbsp;

&nbsp;

\*/15 \* \* \* \* wget -q [http://www.myshop.com/backend/cron](http://www.myshop.com/backend/cron)

---

<div class="post-metadata">

### Author: ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)
#### Post date: [7. Oktober 2019 um 08:43 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/4 "2019-10-07T08:43:29Z")

</div>

You should prefer call the cronjob in the cli. php bin/console sw:cron:run

---

<div class="post-metadata">

### Author: ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)
#### Post date: [9. Oktober 2019 um 05:22 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/5 "2019-10-09T05:22:09Z")

</div>

@Shyim‍ &nbsp;I thought you read my question. Its working in CLI but not call automatically.

---

<div class="post-metadata">

### Author: ![Moritz\_Naczenski](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/moritz_naczenski/32/7792_2.png) [@Moritz\_Naczenski](https://forum.shopware.com/u/Moritz_Naczenski)
#### Post date: [9. Oktober 2019 um 05:44 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/6 "2019-10-09T05:44:49Z")

</div>

Did you add the command to your servers crontab?  
Shopware won’t call this automatically, you need to add a cron on your servers crontab. But this is not a shopware task at all.

&nbsp;

---

<div class="post-metadata">

### Author: ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)
#### Post date: [9. Oktober 2019 um 05:54 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/7 "2019-10-09T05:54:29Z")

</div>

This cron is executing a via CLI using command.&nbsp; How to setup in server

---

<div class="post-metadata">

### Author: ![sacrofano](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@sacrofano](https://forum.shopware.com/u/sacrofano)
#### Post date: [9. Oktober 2019 um 13:37 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/8 "2019-10-09T13:37:41Z")

</div>

Edit the users crontab:

```
crontab -e

```

In my servers crontab for the user „apache“ :

```
*/10 * * * * php /path_to_shopware/bin/console sw:cron:run > /dev/null

```

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)
#### Post date: [11. Oktober 2019 um 05:15 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/9 "2019-10-11T05:15:26Z")

</div>

> [@sacrofano schrieb:](https://forum.shopware.com/profile/25366/sacrofano "sacrofano")
> 
> Edit the users crontab:
> 
> crontab -e
> 
> In my servers crontab for the user „apache“ :
> 
> \*/10 \* \* \* \* php /path\_to\_shopware/bin/console sw:cron:run \> /dev/null
> 
> &nbsp;
> 
> &nbsp;

Issue resolved path to shopware is missing&nbsp;&nbsp;

---

<div class="post-metadata">

### Author: ![Roseanna](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@Roseanna](https://forum.shopware.com/u/Roseanna)
#### Post date: [16. Oktober 2019 um 10:47 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/10 "2019-10-16T10:47:48Z")

</div>

There is a tutorial at [https://www.easycron.com/cron-job-tutorials/how-to-set-up-cron-job-for-shopware](https://www.easycron.com/cron-job-tutorials/how-to-set-up-cron-job-for-shopware) , may be help you set cron job.

---

<div class="post-metadata">

### Author: ![vasims\_zignuts](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@vasims\_zignuts](https://forum.shopware.com/u/vasims_zignuts)
#### Post date: [16. Oktober 2019 um 12:15 UTC](https://forum.shopware.com/t/cron-job-automatic-execution-is-not-wokring/62155/11 "2019-10-16T12:15:21Z")

</div>

Thank you its working
