我想在当前没有包含缓存插件的所有网站上安装WordPress缓存插件。我正在循环所有cPanel用户,但在运行时会得到一些奇怪的结果。一个内胆是:bash循环没有给出预期的结果
for i in $(ls -I . -I .. /var/cpanel/users) ; do
WPPATH=$(find /home/$i/public_html/ -type f -name wp-config.php)
WPPLUGINPATH="$(echo "${WPPATH//wp-config.php/wp-content/plugins/}")"
cd $WPPLUGINPATH
[ -d $WPPLUGINPATH*cache* ] || \
wp --allow-root plugin install cache-enabler --skip-plugins --skip-themes
sleep 3
chown -R $i: $WPPLUGINPATH
echo $WPPLUGINPATH
done
它正在为最,但得到随机点击,如:
/home/userC/public_html/wp-content/plugins/
Error: This does not seem to be a WordPress install.
Pass --path=`path/to/wordpress` or run `wp core download`.
chown: missing operand after ‘userA:’
Try 'chown --help' for more information.
你可以看到的东西是关闭其引用为用户C尚未chown将此路径示数约用户A
它也说明没有WP安装,但如果我手动cd到该目录,我可以运行wp-cli命令并安装插件而不会出现问题。
另一个错误:
/home/userA/public_html/wp-content/plugins/
-bash: [: /home/userB/public_html/wp/wp-content/plugins/: binary operator expected
Warning: cache-enabler: Plugin already installed.
Success: Plugin already installed.
任何帮助,将不胜感激
你不应该使用'为(LS ...'见[**击PItfalls **](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.24.28ls_.2A.mp3.29) –
也相关:[为什么你不应该解析'ls']的输出(http:/ /mywiki.wooledge.org/ParsingLs)和[不要使用'for'读取行]](http://mywiki.wooledge.org/DontReadLinesWithFor) –
此外,使用'set -x'来观察脚本的内容一般来说,在实践中这样做会帮助你提出更好的问题。 –