3

Is there a way to update plugins, themes, and core, all in one row, instead 3 rows, in WPCLI?

This is the current code I use in the crontab and that I'd like to improve:

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
0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && /usr/local/bin/wp theme update --all --allow-root; done
5

Run a script instead:

0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && ./updatewp.sh; done

In updatewp.sh:

wp core update --all --allow-root
wp plugin update --all --allow-root
wp theme update --all --allow-root
  • 1
    Or, perhaps even better, include the for dir ... in the script, and use WP-CLI's --path argument (eg, wp core udpate --all --allow-root --path=$dir). – Pat J Nov 24 '17 at 15:36
1

I'd do something like this:

0 0 * * * for dir in /var/www/html/*/; do cd "$dir" &&  \
( \
    /usr/local/bin/wp core update --allow-root && \
    /usr/local/bin/wp plugin update --all --allow-root && \
    /usr/local/bin/wp theme update --all --allow-root \
); \
done

\ used to break lines up for readability; this should probably be a single line in your crontab, like so:

0 0 * * * for dir in /var/www/html/*/; do cd "$dir" && ( /usr/local/bin/wp core update --allow-root && /usr/local/bin/wp plugin update --all --allow-root && /usr/local/bin/wp theme update --all --allow-root ); done

I haven't tested this. However, I regularly do this from the command line (ie, not in crontab).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.