1

I'm using laravel 5.8 and I created a console command to call a python script (the python module is PyVantagePro);

The command works fine if I run it in console, but when I set up the crontab to automatically run the script I get the error "Exit Code: 127(Command not found)"

Full error log:

Symfony\Component\Process\Exception\ProcessFailedException: The command "pyvantagepro getarchives tcp:5.175.66.169:9002 --start "2019-05-19 07:00" --output /var/www/laravel/storage/stations_data/update_archive_6.csv" failed.

Exit Code: 127(Command not found)

Working directory: /var/www/laravel

Output:
================


Error Output:
================
sh: 1: pyvantagepro: not found
 in /var/www/laravel/app/Console/Commands/getReadings.php:78
Stack trace:
#0 [internal function]: App\Console\Commands\getReadings->handle()
#1 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array)
#2 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#3 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#4 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#5 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array)
#6 /var/www/laravel/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#7 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#8 /var/www/laravel/vendor/symfony/console/Application.php(908): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/laravel/vendor/symfony/console/Application.php(269): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\getReadings), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#10 /var/www/laravel/vendor/symfony/console/Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#11 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(133): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /var/www/laravel/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 {main}
7
  • Are you able to see the command in php artisan list? Commented Jun 2, 2019 at 5:36
  • Yes, the command works fine using php artisan command:name. The problem happens when the command is executed by the cron Commented Jun 2, 2019 at 11:29
  • Any log, that hints some issue? Commented Jun 2, 2019 at 11:30
  • added the full log to the question Commented Jun 2, 2019 at 11:43
  • what us in getReadings.php: line 78? Commented Jun 2, 2019 at 12:19

1 Answer 1

2

Your problem is neither PHP nor Python related but likely the "culprit" is $PATH environmental variable whuch is different for either cron run or cron user (if different). The common workaround is to set full path to the binary you want to execute (so instead of foo you invoke i.e. /usr/bin/foo) or to ensure $PATH used by the cron is set the expected values, pointing to all the locations you want to be searched for invoked binaries. This can be done globally per crontab, by simply adding:

PATH=<value-for-PATH-variable>

to top of your crontab file. To ensure it matches the value you have when running tools from command line simply do

echo $PATH

when in shell and either copy what you have there to your crontab, or copy only these segments (paths) that are related to the pyvantagepro tool that are failing currently (recommended approach).

Sign up to request clarification or add additional context in comments.

1 Comment

Yeahp this worked added my echo $PATH to the crontab and solved the problem. Thanks

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.