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
cd
, consider using the--path=""
parameter/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.