CRON job setting ubuntu

March 11, 2019 808 views
Configuration Management Ubuntu

not able to set cron job

  • * * * * /path/to/your/php 'path/to/cron.php'

i have tried editing the crontab -e

not sure if php path is wrong or something else has to be done.

tried php paths like /usr/bin/php

4 Answers
lampreyOne March 11, 2019
Accepted Answer

If you run:
/path/to/your/php 'path/to/cron.php'
does that work?

the previous server (some other hosting company) where i used to run cron for this script , the code goes like

  • * * * * /opt/php70/bin/php 'path/to/cron/script >/dev/null 2>&1

the cron used to work fine there.

thats what i did as per my first message above, which did not work. Do you mean /path/to/your/php 'path/to/cron.php' without cron expression in front of it?

  • I meant type that in to the console, not adding it to the crontab script.
    You can get your php script running that way, and then when you're satisfied, add it to the crontab (though be careful, cron runs without a lot of environment variables, particularity path that you might have set in your shell)

  • I meant type that in to the console, not adding it to the crontab script.
    You can get your php script running that way, and then when you're satisfied, add it to the crontab (though be careful, cron runs without a lot of environment variables, particularity path that you might have set in your shell)

    • yes when i run /path/to/your/php 'path/to/cron.php' it works, but then if i put these commands in /var/spool/cron/crontabs/root

      it doesn't. Can u guide, if this is wrong step.

      My config has apache2, php7.1 ubuntu 18

    • hey, its working now, just had to reboot the server. thank for your help though.

      and had to install php7.1 again with cli support. which perhaps did the trick.

hello, in a similar situation again, cron not working. I have set root file in crontab folder.

If i run - /path/to/your/php 'path/to/cron.php' on console. The job runs successfully. But not via crontab

its Ubuntu 16.04, php7.1, apache2

since i can run the command in console successfully, what else do you think could be the reason?

  • Solved it by just adding >/dev/null 2>&1 at the end of my cron commands in crontab.
    Silly tool me so much time to figure this out. Nevertheless, for someone else who stumbles upon this issue.

Have another answer? Share your knowledge.