2
votes

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

1
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.aynber
pipe the output(stdout/stderr) of the command into a logfile ....bin/console app:slack >> logfile.log 2>&1JustOnUnderMillions
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?twharmon
Maybe, you have a typo in AppKernel.php. I dont like this part ``` "Sensio\Bundle\Gene$``` of your log file. Regards.Viktor

1 Answers

4
votes

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