WPCLI – update plugins, themes, and core, all in one row, instead 3 rows?

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

Solutions Collecting From Web of "WPCLI – update plugins, themes, and core, all in one row, instead 3 rows?"

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

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).