admin管理员组文章数量:1122846
I have the following WP-CLI command to update all plugins and core. It seems to fail when being executed from cron (other cron commands work):
0 0 * * 0 for dir in /var/www/html/*/; do cd "$dir" && wp plugin update --all --allow-root; wp core update --allow-root; done
I tried to run it manually (did so after a manual update from GUI after a period without updates), I got the following for all sites:
Success: Plugin already updated.
Success: WordPress is up to date.
Why would the command fail on cron?
I tried to debug this by letting the command run each minute (* * * * *
) and checking the output (cron output usually goes to /var/mail/root
).
/var/mail/root output:
Subject: Cron <root@machine_name> for dir in /var/www/html/*/; do cd "$dir" && wp plugin update --all --allow-root; wp core update --allow-root; done
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20170723050601.E8FBF3EF4F@machine_name>
Date: Sun, 23 Jul 2017 05:06:01 +0000 (UTC)
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
I have the following WP-CLI command to update all plugins and core. It seems to fail when being executed from cron (other cron commands work):
0 0 * * 0 for dir in /var/www/html/*/; do cd "$dir" && wp plugin update --all --allow-root; wp core update --allow-root; done
I tried to run it manually (did so after a manual update from GUI after a period without updates), I got the following for all sites:
Success: Plugin already updated.
Success: WordPress is up to date.
Why would the command fail on cron?
I tried to debug this by letting the command run each minute (* * * * *
) and checking the output (cron output usually goes to /var/mail/root
).
/var/mail/root output:
Subject: Cron <root@machine_name> for dir in /var/www/html/*/; do cd "$dir" && wp plugin update --all --allow-root; wp core update --allow-root; done
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20170723050601.E8FBF3EF4F@machine_name>
Date: Sun, 23 Jul 2017 05:06:01 +0000 (UTC)
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
/bin/sh: 1: wp: not found
Share
Improve this question
edited Apr 12, 2024 at 5:13
Jesse Nickles
7357 silver badges19 bronze badges
asked Jul 19, 2017 at 13:45
user124167user124167
111 silver badge2 bronze badges
7
|
Show 2 more comments
1 Answer
Reset to default 1Understanding this answer requires preliminary knowledge in a system administration and Linux issue named "Environment variables". Acquiring this knowledge could be done with a didactic Linux book, course, or tutor. If one explanation was bad, seek another.
The problem and the solution:
It seems to happen due to a partial utilization of the PATH environment variable, by cron.
When cron runs it has only the /usr/bin
value of this variable, instead the whole set, common in Ubuntu 16.04:
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
What I did was to add the full location of WP-CLI to the commands (I also splitted the long one-liner command to two short commands):
From:
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && wp plugin update --all --allow-root; done
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && wp core update --allow-root; done
To:
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp plugin update --all --allow-root; done
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp core update --allow-root; done
Note the /usr/local/bin/
right before wp
.
To test this works without waiting a whole day I changed the cron schedule from 0 0 * * *
(in the first minute, of the first hour, in each day of month, in each month, in each day of week), to this:
* * * * *
(in each minute, in each hour, in each day of month, in each month, in each day of week).
After about 2 minutes I checked one of my websites and saw everything was updated (besides themes, which updating them isn't included in the two commands I used).
本文标签: wp cliWPCLI command to update plugins and core fails in crontab
版权声明:本文标题:wp cli - WP-CLI command to update plugins and core fails in crontab? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310670a1934462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
cd
, consider using the--path=""
parameter – Tom J Nowell ♦ Commented Jul 19, 2017 at 14:19/bin/sh: 1: wp: not found
error implies thewp
executable isn't found when cron is running. If you're using a bash alias to reference WP-CLI, or your bash profile to modify$PATH
, then neither will be loaded automatically in the cron context. – Daniel Bachhuber Commented Jul 24, 2017 at 13:25