0

Im running a PHP web environment on Elastic Beanstalk. Iv tried 6 ways to Sunday to setup a cronjob: following AWS template on cronjobs in the .ebextensions folder, manually creatingn the job in the shell using: crontab -e as suggested here https://stackoverflow.com/questions... and more...

Currently I have this config file in the .ebextensions folder saved as cron-linux.config

files:
  "/etc/cron.d/mycron":
    mode: "000644"
    owner: root
    group: root
    content: |
      */3 * * * * root /var/www/html/crawler/mine.php >/dev/null 2>&1

commands:
  remove_old_cron:
    command: "rm -f /etc/cron.d/mycron.bak"

Please help!

Stefanpt
  • 77
  • 9
  • What is the issue? any error messages? – Marcin May 05 '20 at 09:56
  • I can run the script manually, no problem, but I cnt get it to run every 3 minutes. or on any schedule. Im not seeing any error messages. What do you suggest? – Stefanpt May 05 '20 at 10:30
  • `mine.php` just works as a regular bash script? It does not have to be execute through a regular `bash` script or through php interpreter? – Marcin May 05 '20 at 10:37
  • Actually it has to be executed as a php script, not bash script – Stefanpt May 05 '20 at 10:48
  • Have you checked cron logs in /var/log/cron.log ? – Marcin May 05 '20 at 10:51
  • seems the file has not been created. In the Log directory there is only "cron". trying to open that in nano, says "permission denied" – Stefanpt May 05 '20 at 11:02
  • use `sudo nano` to open or `cat /var/log/cron.log`. – Marcin May 05 '20 at 11:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/213166/discussion-between-stefanpt-and-marcin). – Stefanpt May 05 '20 at 12:25
  • 1
    Update: Thanks to Marcin, the cron is now running. Unfortunately the php script isnt running from the bash script. Any ideas? – Stefanpt May 05 '20 at 13:36

1 Answers1

0

Success!

Steps to fixing the issue:

  1. After using the AWS example Cron Job found HERE,
  2. Run the PHP script from the bash script:

    #!/bin/bash
    
    php -f /var/www/html/mine.php
    
    exit 0
    
  3. Then made "mine.php" executable using

    sudo chmod +x mine.php
    

Two issues:

  1. connection details to the database had to be hard coded as the $SERVER variable didnt work (Not sure why)

  2. the part of the script that sends an email with the results still doesnt work.

Not sure why some things work when running the script from the browser but not in bash? But at least the Cron job is working.

Hope this helps someone

Stefanpt
  • 77
  • 9