使用Bash下载并在wordpress wp-config.php中插入salt字符串

Rog*_*ger 12 wordpress bash sed

如何使用Bash脚本从wordpress 中将变量$ SALT的内容插入文件的特定点(行或字符串),如wp-contet.php?

SALT=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)
Run Code Online (Sandbox Code Playgroud)

la_*_*0ka 15

我不是解析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
Run Code Online (Sandbox Code Playgroud)

好了,现在它已经修复了...它应该找到盐应该去的地方,它将用从https://api.wordpress.org/secret-key/1.1/salt/检索到的信息替换它


luc*_*ell 5

此版本定义了不存在的新密钥,并替换了现有密钥:

#!/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
Run Code Online (Sandbox Code Playgroud)