multisite - How to run nested xargs commands?

I am trying to loop through all sites on a multisite network, and for each site, delete all subscriber users.I have tr

I am trying to loop through all sites on a multisite network, and for each site, delete all subscriber users. I have tried this WP-CLI command:

wp site list --field=url | xargs -n 1 -I ^ wp user list --url=^ --role=subscriber --field=ID | xargs -n 2 -I % ^ wp user delete % --url=^ --reassign=4

I can't find a way to pass the ^ value to the second xargs command. Anyone?

I am trying to loop through all sites on a multisite network, and for each site, delete all subscriber users. I have tried this WP-CLI command:

wp site list --field=url | xargs -n 1 -I ^ wp user list --url=^ --role=subscriber --field=ID | xargs -n 2 -I % ^ wp user delete % --url=^ --reassign=4

I can't find a way to pass the ^ value to the second xargs command. Anyone?

Share Improve this question asked Jul 9, 2019 at 13:56 photocuriophotocurio 761 silver badge7 bronze badges 1
  • 1 that's a lot of piped/chained commands, does it have to be a one liner with pipes? Couldn't you use a bash variable or two? – Tom J Nowell Commented Jul 9, 2019 at 14:48
Add a comment  | 

1 Answer 1

Reset to default 3

xargs is unnecessary, something similar to this will do the job without any piping or xargs:

sites=$(wp site list --field=url)
for site in $sites
do
  users=$(wp user list --url="$site" --role=subscriber)
  for user in $users
  do
    wp user delete $user --url="$site" --reassign=4
  end
end

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745323434a4622548.html

相关推荐

  • multisite - How to run nested xargs commands?

    I am trying to loop through all sites on a multisite network, and for each site, delete all subscriber users.I have tr

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信