# .sh script won't run cronjobs

**URL:** <https://forum.mautic.org/t/sh-script-wont-run-cronjobs/11265>\
**Category:** Product Support\
**Created:** [October 1, 2019, 12:40am UTC](https://forum.mautic.org/t/sh-script-wont-run-cronjobs/11265 "2019-10-01T00:40:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/simas/32/724_2.png) [@simas](https://forum.mautic.org/u/simas)\
**Post date:** [October 1, 2019, 12:40am UTC](https://forum.mautic.org/t/sh-script-wont-run-cronjobs/11265/1 "2019-10-01T00:40:35Z")

</div>

My Mautic version is: 2.15.2  
My PHP version is: 7.2.19

My hosting provider’s cronjobs don’t support certain commands like writing cronjobs results to log files (they have their own modified version of cpanel). For example:

php /home/user/domain.com/public\_html/mautic/app/console mautic:segments:update \> /home/user/domain.com/public\_html/mautic/segments\_update.log 2\>&1 gets me an error that some characters are not supported.

(If I just write php /home/user/domain.com/public\_html/mautic/app/console mautic:segments:update everything is fine and the processes are running on mautic).

So their proposed workaround was to write a script for every cronjob and use it as a cronjob. So my scripts are:

#!/bin/bash  
/usr/bin/php /home/user/domain.com/public\_html/mautic/app/console mautic:segments:update \> /home/user/domain.com/public\_html/mautic/Simo\_cronjobs/my\_cron\_logs/segments\_update.log 2\>&1

and so on.

The hosting provider says that the cronjobs/scripts are executed from their side.  
(the output of cronjob is:  
–2019-09-30 23:40:01-- [https://domain.com/mautic/mautic\_segments\_update.sh](https://domain.com/mautic/mautic_segments_update.sh) Resolving [domain.com](http://domain.com) ([domain.com](http://domain.com))… 2.57.89.23 Connecting to [domain.com](http://domain.com) ([domain.com](http://domain.com))|2.57.89.23|:443… connected. HTTP request sent, awaiting response… 200 OK Length: 238 [application/x-sh] Saving to: â/dev/nullâ 0K 100% 38.1M=0s 2019-09-30 23:40:06 (38.1 MB/s) - â/dev/nullâ saved [238/238]  
)  
so they say the problem is with my scripts. Any ideas what’s wrong? Help needed 🙂

---

<div class="post-metadata">

**Author:** ![virgilwashere](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/virgilwashere/32/554_2.png) [@virgilwashere](https://forum.mautic.org/u/virgilwashere)\
**Post date:** [October 1, 2019, 2:09am UTC](https://forum.mautic.org/t/sh-script-wont-run-cronjobs/11265/2 "2019-10-01T02:09:38Z")

</div>

> [@simas](#):
>
> [https://domain.com/mautic/mautic\_segments\_update.sh](https://domain.com/mautic/mautic_segments_update.sh)

I doubt that is the intended way to invoke the bash script.

### php script option

If you are interested in adding a PHP interface for running the cron commands, have a look at my repo here: [GitHub - virgilwashere/mautic-cron-commands: Script to run Mautic commands from a web page.](https://github.com/virgilwashere/mautic-cron-commands#how-to-use-)

Once installed, you can browse to this page:

> [https://mautic.example.com/commands.php?mautibot\_happy&task=mautic%3Asegments%3Aupdate](https://mautic.example.com/commands.php?mautibot_happy&task=mautic%3Asegments%3Aupdate)

⚠ You need to update the password in the file from `mautibot_happy`

### crontab

For using your script in crontab specifically, try this:

`*/15 * * * * /home/user/domain.com/public_html/mautic/mautic_segments_update.sh > /home/user/domain.com/public_html/mautic/Simo_cronjobs/my_cron_logs/segments_update.log 2>&1`

Two notes:

- this assumes that `/home/user/domain.com/public_html/mautic/mautic_segments_update.sh` is executable. If not, put **`bash`** at the start of the command

`bash /home/user/domain.com/public_html/mautic/mautic_segments_update.sh`

- not sure if your provider needs the _every 15 minutes_ part at the beginning.

And in your script, remove the output redirection:

```
#!/bin/bash
/usr/bin/php /home/user/domain.com/public_html/mautic/app/console mautic:segments:update

```

Virgil  
🇦🇺

---

<div class="post-metadata">

**Author:** ![simas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/simas/32/724_2.png) [@simas](https://forum.mautic.org/u/simas)\
**Post date:** [October 1, 2019, 9:38am UTC](https://forum.mautic.org/t/sh-script-wont-run-cronjobs/11265/3 "2019-10-01T09:38:38Z")

</div>

thank you @virgilwashere for your reply

> [@virgilwashere](#):
>
> > [https://domain.com/mautic/mautic\_segments\_update.sh](https://domain.com/mautic/mautic_segments_update.sh)
> 
> I doubt that is the intended way to invoke the bash script.

well, that’s what I was told to use in the command line to invoke the script… and from the output file support says it’s working from their side…

I didn’t plan to use crontab file but to use hosting providers interface for adding cronjobs (failed when I tried to ad logging ☹ ), then I tried to use script for that (failing up till now ☹ ) , so the third option could be to use crontab file as you say, and if that fails, to change provider who uses a normal cpanel…

> [@virgilwashere](#):
>
> For using your script in crontab specifically, try this:
> 
> `*/15 * * * * /home/user/domain.com/public_html/mautic/mautic_segments_update.sh > /home/user/domain.com/public_html/mautic/Simo_cronjobs/my_cron_logs/segments_update.log 2>&1`
> 
> Two notes:
> 
> - this assumes that `/home/user/domain.com/public_html/mautic/mautic_segments_update.sh` is executable. If not, put **`bash`** at the start of the command

Yes, scripts are executable, but if I’ll use crontab though, I don’t think I need to use my scripts? I’ll type the php commands directly to the crontab…

Not sure if I got that:

> [@virgilwashere](#):
>
> And in your script, remove the output redirection:
> 
> ```auto
> #!/bin/bash
> /usr/bin/php /home/user/domain.com/public_html/mautic/app/console mautic:segments:update
> 
> ```

you mean to remove adding the log file ?  
“/home/user/domain.com/public\_html/mautic/Simo\_cronjobs/my\_cron\_logs/segments\_update.log 2\>&1”

---

<div class="post-metadata">

**Author:** ![simas](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/simas/32/724_2.png) [@simas](https://forum.mautic.org/u/simas)\
**Post date:** [October 2, 2019, 10:36am UTC](https://forum.mautic.org/t/sh-script-wont-run-cronjobs/11265/4 "2019-10-02T10:36:02Z")

</div>

> [@simas](#):
>
> ![](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/1X/373cf42d34c16dd54d96f18d4c3b2c1713ca3931.jpeg) virgilwashere:
> 
> > > [https://domain.com/mautic/mautic\_segments\_update.sh](https://domain.com/mautic/mautic_segments_update.sh)
> > 
> > I doubt that is the intended way to invoke the bash script.
> 
> well, that’s what I was told to use in the command line to invoke the script… and from the output file support says it’s working from their side…

found the issue. Yes, the problem was with hosting support giving the wrong instructions to invoke the script and saying that everything is ok from their side… that says a lot about their support 💩:…
