【问题标题】:Update Salt Shell Script更新 Salt Shell 脚本
【发布时间】:2014-11-04 21:09:00
【问题描述】:

我有一个脚本

#!/bin/bash
chars=( {a..z} {A..Z} {0..9} \, \; \. \: \- \_ \# \* \+ \~ \! \§ \$ \% \& \( \) \= \? \{ \[ \] \} \| \> \< )

function rand_string {  
local c=$1 ret=  
while((c--)); do  
ret+=${chars[$((RANDOM%${#chars[@]}))]}  
done  
printf '%s\n' "$ret"  
}  
for i in {1..8}  
do  
export salt$i=$(rand_string 64)  
done  

echo $salt1  
echo $salt2  

sed -i 's/put your unique phrase here/'$salt1'/g' /var/www/testsite/wp-config.php  
sed -i 's/put your unique phrase here/'$salt2'/g' /var/www/testsite/wp-config.php  

我在屏幕上看到的输出是:

[root@server testsite]# ./salt.sh  
$,E5:2nB$p>s;2Y)h>}VU2V5Lj2UC38,yY+0?{LM;rt;Xx%B:#%9z2oc-BSE;1%Z  
~#&2#p#hZkT+)p83ZD%7=noy?§xbx%3iP4*|z<-haHXVIk<[IR0>v%.r*+X5=kNl  

但是我的 wp-config.php 包含

define('AUTH_KEY',         '$,E5:2nB$p>s;2Y)h>}VU2V5Lj2UC38,yY+0?{LM;rt;Xx%B:#%9z2oc-BSE;1%Z');  
define('SECURE_AUTH_KEY',  '$,E5:2nB$p>s;2Y)h>}VU2V5Lj2UC38,yY+0?{LM;rt;Xx%B:#%9z2oc-BSE;1%Z');  

我也尝试将 SED 语句放入我的循环中,但不知道如何调用该变量。

sed -i 's/put your unique phrase here/'$salt$i'/g' /var/www/testsite/wp-config.php  

wp-config.php 包含

define('AUTH_KEY',         '1');  
define('SECURE_AUTH_KEY',  '1');  

我该如何解决这个问题。

我想看到的是

define('AUTH_KEY',         '$,E5:2nB$p>s;2Y)h>}VU2V5Lj2UC38,yY+0?{LM;rt;Xx%B:#%9z2oc-BSE;1%Z');  
define('SECURE_AUTH_KEY',  '~#&2#p#hZkT+)p83ZD%7=noy?§xbx%3iP4*|z<-haHXVIk<[IR0>v%.r*+X5=kNl');  

【问题讨论】:

    标签: php wordpress shell sed


    【解决方案1】:

    put your unique phrase here 在这两行中。第一个 sed 替换了两个实例。

    这样的事情应该可以工作:

    sed -i -e '/put your unique phrase here/{s/put your unique phrase here/'"$salt1"'/;N;s/put your unique phrase here/'$salt2'/}' wp-config.php
    

    仅在与该字符串匹配的行上运行命令。当匹配时执行第一次替换,将下一行读入模式空间并执行第二次替换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      相关资源
      最近更新 更多