简体   繁体   English

在bash脚本中执行symfony命令

[英]Execute symfony command in bash script

I can't get to execute symfony command in bash script when I run it in cron . cron运行时,我无法在bash脚本中执行symfony命令。 When I execute the .sh script by hand everything is working fine. 当我手动执行.sh脚本时,一切工作正常。

in my bash file the command is executed like this: 在我的bash文件中,命令是这样执行的:

/usr/bin/php -q /var/www/pww24/bin/console pww24:import asari $office > /dev/null

I run the scripts from root, the cron is set to root as well. 我从root运行脚本,将cron也设置为root。 For the test i set files permissions to 777 and added +x for execution. 对于测试,我将文件权限设置为777并添加了+x来执行。

the bash script executes fine. bash脚本执行正常。 It acts like it's skipping the command but from logs i can see that the code is executed 它的行为就像是跳过命令,但是从日志中我可以看到代码已执行

It turned out that symfony system variables that I have stored on server are not enough. 原来,我存储在服务器上的symfony系统变量还不够。 When you start to execute the command from command line its fine, but when using Cron you need them in .env file. 从命令行开始执行命令就可以了,但是使用Cron时,您需要在.env文件中使用它们。 Turned out that in the proces of countinous integrations I only got .env.dist file and I've to make the .env file anyways. 事实证明,在大量集成过程中,我只获得了.env.dist文件,而且无论如何我都必须制作.env文件。 Additionaly I've added two lines to cron: 另外,我在cron中添加了两行:

PATH=~/bin:/usr/bin/:/bin
SHELL=/bin/bash

and run my command like this from the bash file: 然后从bash文件运行我的命令:

sudo /usr/bin/php -q /var/www/pww24/bin/console pww24:import asari $office > /dev/null

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM