0

I want to set up a cronjob to do me a git pull and other bits and pieces.

my job looks like this:

cd /var/www/project; git pull; composer install; composer update;

But it never works I tried making changes locally, and push that and I have never seen the changes I have to git pull manually, Why is this happening? I don't know why I get bullet points here these are stars.

in a cron.log I get:

Jun 14 09:38:32 ip-172-31-24-22 cron[19247]: (CRON) INFO (pidfile fd = 3)
Jun 14 09:38:32 ip-172-31-24-22 cron[19247]: (CRON) INFO (Skipping @reboot jobs -- not $
Jun 14 09:39:01 ip-172-31-24-22 CRON[19256]: (root) CMD (php /var/www/project/artisa$
Jun 14 09:39:01 ip-172-31-24-22 CRON[19257]: (root) CMD (cd /var/www/project; git pu$
$ionclean ] && /usr/lib/php/sessionclean)
Jun 14 09:39:02 ip-172-31-24-22 CRON[19254]: (CRON) info (No MTA installed, discarding $

//

Already up-to-date.
/bin/sh: 1: composer: not found
/bin/sh: 1: composer: not found
danglingpointer
  • 4,708
  • 3
  • 24
  • 42
Przemek
  • 834
  • 6
  • 21
  • 49
  • Login into the cron's user, navigate to his home and execute the command to see what going on – Arount Jun 14 '17 at 08:32
  • Have you tried it with at least one digit instead of only stars? You can also try to put */ in front, don't know why but worked for me. – Maikel Jun 14 '17 at 08:32
  • Also go through this [question](https://stackoverflow.com/questions/4883069/debugging-crontab-jobs) – hurturk Jun 14 '17 at 08:33
  • I have added cron.log does that tell anyone? – Przemek Jun 14 '17 at 08:40
  • The output of a cron job is sent back to the crontab owner using email. The cron daemon cannot find any email program installed on your system and it couldn't sent the output by email. It complains about it in the log (`No MTA installed, discarding output`). – axiac Jun 14 '17 at 08:51
  • I actually installed a mail and somehow it does give me and output, it does git pull as it says it's up to date but my composer is not found? does that I mean I have to go to the directory again? see another edit – Przemek Jun 14 '17 at 08:52
  • When you run `composer` without specifying a path, the shell searches the binary inside the directories specified in the `$PATH` environment variable. The cron daemon runs with a different value for `$PATH`. You can override it on the top of the `crontab` file, or specify the full path of `composer` in the command. Even better, put all the configurations and commands in a shell script and put the full path of this script in `crontab`. This way you have more room to configure and run whatever commands you need. – axiac Jun 14 '17 at 08:55
  • for now let's say I specify the full path of composer in crontab, how do I do that? I don't even know where it is, if I type composer anywhere it works – Przemek Jun 14 '17 at 08:57

1 Answers1

1

So, to fix /bin/sh: 1: composer: not found you can set absolute path instead of program name.

To know where is composer:

$ whereis composer
composer: /usr/bin/composer /usr/share/man/man1/composer.1.gz

What you need here is /usr/bin/composer.

So you can update your cron line according to that:

* * * * * cd /var/www/project && git pull && /usr/bin/composer install && /usr/bin/composer update

Btw, here are some tips:

  • Do not start cron line by five stars, it's really not a good practice.
  • Prefer events to crons - like git hooks, in this case, you should use githooks.
  • When you want to execute several bash commands within one line, use && and not ; (unless you know what you are doing).
  • I don't know if it's a good practice, but you may use absolute path for every program called in your crontab. (/usr/bin/git).
  • Using cd within a cron line is not that great, you should look if you can add arguments to git & composer command to run it from anywhere with the same behaviour.
Arount
  • 9,853
  • 1
  • 30
  • 43