Can't run a command from crontab?

I want to update some things in my database every day at 16:00.

Therefore, I use crontab, which executes a command in which the file.php file is launched, which starts the update. It works fine when I execute a command in bash, but there is a problem with crontab.

crontab:

00 16 * * * ./etc/cron.daily/maj_cat 

maj_cat

 php var/www/dev/update.php 

Thanks!

+4
source share
4 answers

./etc/cron.daily/maj_cat - the relative path, as well as var / www / dev / update.php, try:

 00 16 * * * /etc/cron.daily/maj_cat 

and maj_cat:

 php /var/www/dev/update.php 

You can:

 00 16 * * * /usr/bin/env php /var/www/dev/update.php 
+3
source

You want to use the full path to PHP,

enter: whereis php

usually php is in / usr / bin / php

leads to: /usr/bin/php/var/www/dev/update.php

I find it useful to verify that crontab is executed by output to a file, so you know that cron is actually running, for example:

/usr/bin/php/var/www/dev/update.php> output.txt

You will probably be better off putting a forward slash before β€œvar”, as shown above.

+1
source

Crondeaemon is probably not using the PATH variable, which is set when you do it manually. Make sure php is on the way (at the beginning of your crontab).

Otherwise, you can try using absolute paths in the script.

+1
source

Cron uses the default profile when it runs cronjobs, which will probably have a different PATH variable than what you use when you log in. You can upload your own profile at the beginning of cronjob to make sure that the cronjob environment matches your logged in user.

You can upload your profile this way:

 00 16 * * * ~/.profile; ./etc/cron.daily/maj_cat 
0
source

All Articles