0

I have a Symfony (PHP) command on Amazon Linux deployed to Elastic Beanstalk. I've added a cron job. All looks fine. The cron job runs, creates log file in /tmp folder but it's empty - there should be at least a few characters each time command is executed. I've seen a few posts here about running cron jobs but none of them worked - the closes to mine issue is this one.

The trick is that if I SSH to the instance and run this command manually all start working as expected. Cron runs the command every time it is set to run. But I need to run it for the first time manually, otherwise it won't be executed correctly.

I run PHP command through script.sh in which I have #!/bin/bash.

The question is why this needs to be run manually first and the it runs from cron. Otherwise it doesn't. I've set log file permissions to 0666 so anyone can write to it but no luck.

I deploy my Symfony command to Elastic Beanstalk. If I'd have only one EC2 instance that wouldn't be a problem, but I use Elastic Beanstalk to scale it and need it to run without manual initialization.

Any help appreciated. Thanks

Community
  • 1
  • 1
Strabek
  • 2,391
  • 3
  • 32
  • 39

1 Answers1

1

Finally, after 3 hours I got it working thanks to this post and Robert Brisita's answer.

In crontab -e file:

SHELL=/bin/bash

*/1 * * * * $HOME/cron_job.sh

In cron_job.sh file:

#!/bin/bash

source $HOME/.bash_profile

some_other_cmd

The trick is to enable env vars to cron. Otherwise I was getting Symfony errors. I did not see them because I had output to file in wrong place. It was in script.sh file instead in crontab.

Now all works as expected.

Community
  • 1
  • 1
Strabek
  • 2,391
  • 3
  • 32
  • 39