admin管理员组文章数量:1122832
These are my very first steps with bash scripts and I have an issue.
I want to list all plugins and themes in the directory of the website, which have available updates:
1 #!/bin/bash
2
3 #check for updates of plugins, themes and core version in a WordPress installations
4
5 str1="available"
6 str2="none"
7
8 wp plugin list | grep available | awk '{print $1, $2, $3, $4}'
9
10 if [ "$str1" == "$str2" ]; then
11 echo "Updates available"
12 else
13 echo "No updates available"
14 fi
15
16
17 wp theme list | grep available | awk '{print $1, $2, $3, $4}'
18
19 if [ "$str1" == "$str2" ]; then
20 11 echo "Updates available"
21 12 else
22 13 echo "No updates available"
23 14 fi
However, if I execute the script, the following output appears:
No updates available updates_check: line 26: syntax error: unexpected end of file
I've tried to find a solution over the web. Can you please share how the script should be ended? Thank you!
These are my very first steps with bash scripts and I have an issue.
I want to list all plugins and themes in the directory of the website, which have available updates:
1 #!/bin/bash
2
3 #check for updates of plugins, themes and core version in a WordPress installations
4
5 str1="available"
6 str2="none"
7
8 wp plugin list | grep available | awk '{print $1, $2, $3, $4}'
9
10 if [ "$str1" == "$str2" ]; then
11 echo "Updates available"
12 else
13 echo "No updates available"
14 fi
15
16
17 wp theme list | grep available | awk '{print $1, $2, $3, $4}'
18
19 if [ "$str1" == "$str2" ]; then
20 11 echo "Updates available"
21 12 else
22 13 echo "No updates available"
23 14 fi
However, if I execute the script, the following output appears:
No updates available updates_check: line 26: syntax error: unexpected end of file
I've tried to find a solution over the web. Can you please share how the script should be ended? Thank you!
Share Improve this question asked Aug 20, 2020 at 9:10 zamunda68zamunda68 11 Answer
Reset to default 0WP-CLI and AWK
One way is to do the counting of the available
string in the third column via AWK:
wp plugin list | \
awk 'BEGIN{N=0;} \
($3=="available"){N++; print $0;} \
END{print(N>0)?"Plugin updates available: "N:"No plugin updates available";}'
where N
is the number of available updates, in case you need the number, $0
is the whole row and $3
the third column.
Example output:
Foo-plugin active available 1.2.3
Plugin updates available: 1
Similar for themes.
WP-CLI and PHP/WordPress API
Another way is to do this via a PHP script, that includes the relevant WordPress API calls and run it like:
wp eval-file script.php
or as a custom WP-CLI command.
See e.g. my answer here and here.
本文标签: pluginsBash script to check available updates
版权声明:本文标题:plugins - Bash script to check available updates 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736294830a1929442.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论