如何使用Bash脚本在wp-contet.php这样的文件的特定点(行或字符串)中插入变量$SALT 的内容?
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)发布于 2011-06-03 23:16:33
我不是bash中解析文本文件的专家,但是您应该删除定义从wordpress salt下载的内容的行,然后在末尾插入变量…类似于:
#!/bin/sh
SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
STRING='put your unique phrase here'
printf '%s\n' "g/$STRING/d" a "$SALT" . w | ed -s wp-config.php好了,现在修好了..。它应该查找盐的去向,并将其替换为从https://api.wordpress.org/secret-key/1.1/salt/检索到的信息。
发布于 2013-05-05 21:22:31
如果不存在,此版本将定义新的键,并替换现有的键:
#!/bin/bash
find . -name wp-config.php -print | while read line
do
curl http://api.wordpress.org/secret-key/1.1/salt/ > wp_keys.txt
sed -i.bak -e '/put your unique phrase here/d' -e \
'/AUTH_KEY/d' -e '/SECURE_AUTH_KEY/d' -e '/LOGGED_IN_KEY/d' -e '/NONCE_KEY/d' -e \
'/AUTH_SALT/d' -e '/SECURE_AUTH_SALT/d' -e '/LOGGED_IN_SALT/d' -e '/NONCE_SALT/d' $line
cat wp_keys.txt >> $line
rm wp_keys.txt
done发布于 2015-11-02 17:33:07
如果您有可用的csplit,您可以将原始的wp-config.php文件拆分到盐类定义的任何一边,下载新的盐类,然后将cat重新组合在一起。这使得PHP define()语句保持在wp-config.php中相同的位置,而不是将它们移动到文件中的不同位置:
# Download new salts
curl "https://api.wordpress.org/secret-key/1.1/salt/" -o salts
# Split wp-config.php into 3 on the first and last definition statements
csplit wp-config.php '/AUTH_KEY/' '/NONCE_SALT/+1'
# Recombine the first part, the new salts and the last part
cat xx00 salts xx02 > wp-config.php
# Tidy up
rm salts xx00 xx01 xx02https://stackoverflow.com/questions/6233398
复制相似问题