.sh script won't run cronjobs

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 Resolving domain.com (domain.com)… 2.57.89.23 Connecting to domain.com (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 :slight_smile:

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.

Once installed, you can browse to this page:

https://mautic.example.com/commands.php?mautibot_happy&task=mautic%3Asegments%3Aupdate

:warning: 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
:australia:

thank you @virgilwashere for your reply

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 :frowning: ), then I tried to use script for that (failing up till now :frowning: ) , 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…

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:

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”

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 :poop::…

1 Like