如何在 wp-config.php 中 grep Wordpress 的 DB_NAME、DB_USER、DB_PASSWORD 和 DB_HOST
此 grep 语句从 wp-config.php 中筛选出 DB_NAME、DB_USER、DB_PASSWORD 和 DB_HOST 内容:
example-3.txt
例如,从 wp-config.php 行
example-2.php
它将提取 techoverflow。
以下是 DB_NAME、DB_USER、DB_PASSWORD 和 DB_HOST 的语句:
example-1.txt
DB_USER=$(grep -oP "define\(['\"]DB_USER['\"],\s*['\"]\K[^'\"]+(?=[\'\"]\s*\)\s*;)" wp-config.php)
DB_PASSWORD=$(grep -oP "define\(['\"]DB_PASSWORD['\"],\s*['\"]\K[^'\"]+(?=[\'\"]\s*\)\s*;)" wp-config.php)
DB_HOST=$(grep -oP "define\(['\"]DB_HOST['\"],\s*['\"]\K[^'\"]+(?=[\'\"]\s*\)\s*;)" wp-config.php)你可以在自动备份脚本中使用此功能,而无需手动将密码复制到备份脚本
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow