0

Hi guys i have the next problem(sorry for my english):

I want to executate a command in Mautic cron job, i put the next comands:

*/1 * * * * /usr/local/bin/php /apps/mautic/htdocs/app/console mautic:segments:update

*/1 * * * * /usr/local/bin/php /apps/mautic/htdocs/app/console mautic:campaigns:update

*/1 * * * * /usr/local/bin/php /apps/mautic/htdocs/app/console mautic:campaigns:trigger

I try a lot of things but no one of them work, like:

*/1 * * * *  root /usr/local/bin/php /apps/mautic/htdocs/app/console  mautic:segments:update

or

*/1 * * * * bitnami php /apps/mautic/htdocs/app/console  mautic:segments:update

But i don't know what fail's,if it's the user name,the route to php,the comand,if they doesn't have permission...

If i put this manually work perfectly

php /apps/mautic/htdocs/app/console  mautic:segments:update

ty so much

Community
  • 1
  • 1
ferran
  • 3
  • 6
  • can you locate the php by this command? `which php` – Ben Dec 07 '17 at 10:01
  • Manually yes but i think it doesnt work on the crontab.But i dont know the route of the php,can u help me? – ferran Dec 07 '17 at 10:05
  • can you type this command `which php` in terminal and give the output here? – Ben Dec 07 '17 at 10:08
  • it return me this: /opt/bitnami/php/bin/php. But i put the command in the crontab and doesn't work too: */1 * * * * root /opt/bitnami/php/bin/php apps/mautic/htdocs/app/console mautic:segments:update – ferran Dec 07 '17 at 10:12
  • You may need to check the crontab syntax. It composes by two parts, five fields for day, date, time and followed by command. how about `*/1 * * * * /opt/bitnami/php/bin/php apps/mautic/htdocs/app/console mautic:segments:update`? – Ben Dec 07 '17 at 10:18
  • The comand i put manually to work is: php /apps/mautic/htdocs/app/console mautic:segments:update. So what is your recomendation? – ferran Dec 07 '17 at 10:21
  • Apparently you are using incorrect path of php `/usr/local/bin/php`. Replaced the correct path `/opt/bitnami/php/bin/php` should solve the problem. You are no need to add username before the command. – Ben Dec 07 '17 at 10:24
  • `which php` helps you locate the path of **php** program – Ben Dec 07 '17 at 10:25
  • i know what you are trying to tell me but if php run like a program I think I don't need to put the real route on the crontab no? – ferran Dec 07 '17 at 10:27
  • crontab no sense of the path, so you need to add the full path of crontab. You can run the **php** program, because your user have setup the environment, you can run `echo $PATH` on terminal, when bash lookup the **php** program, it will search through all the paths defined in your user environment variable $PATH. – Ben Dec 07 '17 at 10:33
  • okay finally it's like: */1 * * * * /opt/bitnami/php/bin/php /home/bitnami/apps/mautic/htdocs/app/console mautic:segments:update . But still not working,can be probably cause the second part of the comand don't read it like a only one comand? – ferran Dec 07 '17 at 10:36
  • Can you dump and check the program output? You may change the crontab command to `*/1 * * * * /opt/bitnami/php/bin/php /home/bitnami/apps/mautic/htdocs/app/console mautic:segments:update 2>&1 >> /tmp/output.log` and check the log file. – Ben Dec 07 '17 at 10:42
  • it returns:Failed to lock /opt/bitnami/apps/mautic/htdocs/app/cache/prod/../run/sf.mautic-segments-update.5415eaf7823c0a036b252ba8a9f1f4065263e1c60a23cacf6b5851144245b8c9.lock . Script in progress. Can force execution by using --force. Failed to lock /opt/bitnami/apps/mautic/htdocs/app/cache/prod/../run/sf.mautic-segments-update.5415eaf7823c0a036b252ba8a9f1f4065263e1c60a23cacf6b5851144245b8c9.lock . Script in progress. Can force execution by using --force. – ferran Dec 07 '17 at 10:46
  • it can be because i dont use sudo? if i put sudo at the start of the command¿? – ferran Dec 07 '17 at 10:47
  • probably don't have enough permission to access the folder. you may need to check the user executed the command has enough permission to access the cache folder – Ben Dec 07 '17 at 10:49
  • you might need to add the cron job to root user. sudo won't work in cron job. – Ben Dec 07 '17 at 10:50
  • Man it finally work! is for the sudo: */1 * * * * sudo /opt/bitnami/php/bin/php /home/bitnami/apps/mautic/htdocs/app/console mautic:segments:update. So ty for all the help – ferran Dec 07 '17 at 10:53
  • Please mark me as a accepted answer, thanks. – Ben Dec 07 '17 at 11:13

2 Answers2

1

You should check whether the path of the php program correct. You can check the the full path of the php program in terminal output by this command:

which php

To create a cron job, should always use the full path of the program. The crontab default environment is not like the logged in user. The program may not be found if the path is not defined to the crontab environment.

The crontab syntax composed of two parts, datetime to execute & command to be executed. User is not required to add before the command.

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
Ben
  • 5,069
  • 4
  • 18
  • 26
1

I had the same problem, it turns out that my root user wasn't enabled, therefore there wasn't any way for the system to log in with a root account to perform the cronjobs.

I just made sure that I had my root account enabled with a valid pasword.

Check that by typing:

sudo passwd --status root

If this is the case, just try to change your root password

 sudo passwd root
vmansur
  • 41
  • 6