Problem parsing plugin list from file
I'm trying to install a list of plugins from a text file. This file contains the output of wp plugin list command. Because i saw in the docs that you can merge commands like this to reinstall a bunch of plugins.
wp plugin install $(wp plugin list --field=name)
Anyhow, this text file is created in a separate process.
wp plugin list --fields=name,version | tee plugin_list.txt
But when i tried to run the install command using this list..
wp plugin install $(cat plugin_list.txt)
It gives me weird output.
: Plugin not found.-----------------------+---------+
' plugin could not be found.-------------------+---------+
Warning: |: Plugin not found.
Warning: The '|' plugin could not be found.
Warning: name: Plugin not found.
Warning: The 'name' plugin could not be found.
Warning: |: Plugin not found.
Warning: The '|' plugin could not be found.
Warning: version: Plugin not found.
Warning: The 'version' plugin could not be found.
: Plugin not found.
' plugin could not be found.
: Plugin not found.-----------------------+---------+
' plugin could not be found.-------------------+---------+
Warning: |: Plugin not found.
Warning: The '|' plugin could not be found.
Warning: akismet: Plugin already installed.
Warning: |: Plugin not found.
Warning: The '|' plugin could not be found.
Warning: 4.1.4: Plugin not found.
Warning: The '4.1.4' plugin could not be found.
: Plugin not found.
' plugin could not be found.
Warning: |: Plugin not found.
Warning: The '|' plugin could not be found.
Warning: all-in-one-wp-migration: Plugin already installed.
EDIT: here's the contents of the plugin_list.txt file.
+--------------------------------+---------+
| name | version |
+--------------------------------+---------+
| akismet | 4.1.4 |
| all-in-one-wp-migration | 7.19 |
| all-in-one-seo-pack | 3.4.2 |
| amp | 1.5.2 |
| wp-cloud-mgmt-console | 1.2 |
| google-analytics-for-wordpress | 7.10.4 |
| hello | 1.7.2 |
| jetpack | 8.4.1 |
| simple-tags | 2.5.7 |
| w3-total-cache | 0.13.2 |
| wp-mail-smtp | 1.9.0 |
+--------------------------------+---------+
Any ideas? Is this even doable?
@rizkysyazuli This is passible with same small changes to the process, for example use
wp plugin list --fields=name,version --format=csv | tee plugin_list.txt
Moreover, GitHub issues are meant for enhancement requests and specific, reproducible bugs, not for general support questions. For WP-CLI support options, please review http://wp-cli.org/#support
The easiest way to get support is to join us in the #cli channel on the Make WordPress Slack Team.
Understood. Pls forgive me then. But i still got questionable outputs though from the wp plugin install command. I'm not sure if it's a bug or not..
Again, this is the updated list using csv format.
name
akismet
all-in-one-wp-migration
all-in-one-seo-pack
amp
wp-cloud-mgmt-console
google-analytics-for-wordpress
hello
jetpack
simple-tags
w3-total-cache
wp-mail-smtp
And this is the log from wp plugin install $(cat ./wordpress/plugin_list.csv).
: Plugin not found.
' plugin could not be found.
: Plugin already installed.
' plugin could not be found.
: Plugin already installed.ation
' plugin could not be found.migration
: Plugin already installed.k
' plugin could not be found.-pack
: Plugin already installed.
' plugin could not be found.
: Plugin not found.gmt-console
' plugin could not be found.console
: Plugin already installed.or-wordpress
' plugin could not be found.cs-for-wordpress
: Plugin not found.
' plugin could not be found.
: Plugin already installed.
' plugin could not be found.
: Plugin already installed.
' plugin could not be found.
: Plugin already installed.
' plugin could not be found.
: Plugin already installed.
' plugin could not be found.
Error: No plugins installed.
All 11 plugins in the list are already installed. Although not activated. I expect to get 11 lines of notification saying they're already installed. Not this.
I'm still trying out WP-CLI. So these commands ran on the same WP installation. Which is served from Bitnami WordPress Docker image.
Here's the output of wp --info.
OS: Linux 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019 x86_64
Shell:
PHP binary: /opt/bitnami/php/bin/php
PHP version: 7.4.4
php.ini used: /opt/bitnami/php/lib/php.ini
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: /
WP-CLI packages dir:
WP-CLI global config: /opt/bitnami/wp-cli/conf/wp-cli.yml
WP-CLI project config:
WP-CLI version: 2.4.0
Please check this if you wont to use exact plugin version
#!/bin/bash
FILE='pl.txt'
wp plugin list --fields=name,version --format=csv > $FILE
tail -n +2 "$FILE" > "$FILE.tmp" && mv "$FILE.tmp" "$FILE"
while IFS=$(echo ',') read name version
do
wp plugin install $name --version=$version --force --activate
done < $FILE > $FILE.log
and use tail combined with --force parameter to wp plugin install if installing latest version is acceptable. Skip --force if you wont only activate those plugins - see wp plugin install documentation for details.
Ah, i see. So i have to loop through the list and install one at a time. Got it then.