duanlvxi8652 2017-04-23 09:58
浏览 63

PHP Symfony命令在cron手动运行之前无法运行

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

  • 写回答

1条回答 默认 最新

  • douhuxi4145 2017-04-23 10:49
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动