我有这个脚本:
DB_ARRAY=(NAME USER PASSWD SERVER)
for i in ${DB_ARRAY[@]}; do
VAR="DB_$i"
declare $VAR=$(sed -rn "/_${VAR}_/ { s/.*'_${VAR}_', '(\w+)'\);/\1/p }" ${PRESTASHOP_PATH}/config/settings.inc.php | tail -1)
done
mysqldump -u"${DB_USER}" -p"${DB_PASSWD}"-h"${DB_SERVER}" "${DB_NAME}" > ${DATABASE_PATH}
我基本上是用它来从Prestashop配置中获取数据库变量来进行数据库转储。它适用于Linux。
但是今天我在新系统上尝试时得到了这个:
sed: 1: "/_DB_NAME_/ { s/.*'_DB_ ...": bad flag in substitute command: '}'
sed: 1: "/_DB_USER_/ { s/.*'_DB_ ...": bad flag in substitute command: '}'
sed: 1: "/_DB_PASSWD_/ { s/.*'_D ...": bad flag in substitute command: '}'
sed: 1: "/_DB_SERVER_/ { s/.*'_D ...": bad flag in substitute command: '}'
事实证明,我尝试过的系统是FreeBSD。
已添加: 这是示例settings.inc.php文件,我正在使用sed进行解析:
define('_DB_SERVER_', 'mariadb');
define('_DB_NAME_', 'mydatabase');
define('_DB_USER_', 'prestashop');
define('_DB_PASSWD_', 'prestashop');
define('_DB_PREFIX_', 'ps_');
define('_MYSQL_ENGINE_', 'InnoDB');
define('_PS_CACHING_SYSTEM_', 'CacheFs');
define('_PS_CACHE_ENABLED_', '0');
define('_COOKIE_KEY_', 'xyz');
define('_COOKIE_IV_', 'xyz');
define('_PS_CREATION_DATE_', '2015-04-30');
define('_PS_VERSION_', '1.6.1.0');
define('_RIJNDAEL_KEY_', 'xyz');
define('_RIJNDAEL_IV_', 'xyz');
define('_PS_DIRECTORY_', '/../../');