3

I found two similar questions, but wasn't helped by them.

I have a Symfony command that is working when I enter:

/usr/bin/php /home/bob/example_project/bin/console app:slack

I tried to make a crontab (run every minute) with sudo crontab -e:

MAILTO=""

* * * * * /usr/bin/php /home/bob/example_project/bin/console app:slack

But it's not working. I can't find any error messages either. sudo grep CRON /var/log/syslog gives:

Apr 10 13:21:01 example_project CRON[23432]: (root) CMD (/usr/bin/php /home/bob/example_project/bin/console app:slack)

Using sudo crontab -e -u bob or sudo crontab -e -u www-data doesn't change anything.

What could I be doing wrong?

  • EDIT The logfile.log has this:

PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "SensioGeneratorBundle" from namespace "Sensio\Bundle\Gene$ Did you forget a "use" statement for another namespace? in /home/bob/example_project/app/AppKernel.php:25 Stack trace: 0 /home/bob/example_project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(403): AppKernel->registerBundles() 1 /home/bob/example_project/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(113): Symfony\Component\HttpKernel\Kernel->initializeBundles() 2 /home/bob/example_project/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(68): Symfony\Component\HttpKernel\Kernel->boot() 3 /home/bob/example_project/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(120): Symfony\Bundle\FrameworkBundle\Console\Application->doRun(Object(Sy$ 4 /home/bob/example_project/bin/console(28): S in /home/bob/example_project/app/AppKernel.php on line 25

4
  • According to your log, it looks to be running correctly. Try some logging in your command to verify that everything is running as it should. Maybe it's hitting an error somewhere. Also try adding your email address to the MAILTO in your crontab so that you'll receive the error notifications. Commented Apr 10, 2017 at 13:31
  • 2
    pipe the output(stdout/stderr) of the command into a logfile ....bin/console app:slack >> logfile.log 2>&1 Commented Apr 10, 2017 at 13:33
  • I fixed it with: * * * * * export SYMFONY_ENV=prod && /usr/bin/php /home/bob/example_project/bin/console app:slack. Is there a better way or is this fine? Commented Apr 10, 2017 at 13:45
  • Maybe, you have a typo in AppKernel.php. I dont like this part ``` "Sensio\Bundle\Gene$``` of your log file. Regards. Commented Apr 10, 2017 at 14:49

1 Answer 1

6

There was an environment issue. This fixed it:

SYMFONY_ENV=prod

* * * * * php /home/bob/example_project/bin/console app:slack

There was no need for the full path to php, /usr/bin/php.

As mentioned in the comments, this also works:

* * * * * php /home/bob/example_project/bin/console app:slack -e prod
Sign up to request clarification or add additional context in comments.

1 Comment

Or just * * * * * php /home/bob/example_project/bin/console app:slack -e prod

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.