1

I can't get to execute symfony command in bash script when I run it in cron. When I execute the .sh script by hand everything is working fine.

in my bash file the command is executed like this:

/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. For the test i set files permissions to 777 and added +x for execution.

the bash script executes fine. It acts like it's skipping the command but from logs i can see that the code is executed

4
  • Where is your $office var defined? Can you redirect the output to a file? This will be a nice indicator of what is happening when the job is running as cron. You may also need to redirect stderr with 2>&1 Commented Jan 4, 2019 at 14:06
  • @itChi $office works fine as I can see it in logs. Plus When I hard code the variable it doesn't work either Commented Jan 4, 2019 at 14:11
  • Do you have full path in $office variable? Commented Jan 4, 2019 at 14:13
  • @RomeoNinov $office is a simple string and while executing it from cron it works fine - I can see it in logs, plus the rest of the bash script depends on it and that works fine as well Commented Jan 4, 2019 at 14:18

1 Answer 1

1

It turned out that symfony system variables that I have stored on server are not enough. When you start to execute the command from command line its fine, but when using Cron you need them in .env file. Turned out that in the proces of countinous integrations I only got .env.dist file and I've to make the .env file anyways. Additionaly I've added two lines to cron:

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

and run my command like this from the bash file:

sudo /usr/bin/php -q /var/www/pww24/bin/console pww24:import asari $office > /dev/null
Sign up to request clarification or add additional context in comments.

Comments

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.