I have a script
#!/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 '%sn' "$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
The output I see to my screen is:
[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
However my wp-config.php contains
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');
I also tried to put the the SED statement in my loop however could not figure out how to call the variable.
sed -i 's/put your unique phrase here/'$salt$i'/g' /var/www/testsite/wp-config.php
wp-config.php contains
define('AUTH_KEY', '1');
define('SECURE_AUTH_KEY', '1');
How can I fix this.
What i would like to see is
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');
put your unique phrase here
is in both lines. The first sed replaces both instances.Something like this should work:
Only run the commands on a line that matches that string. When it matches perform the first replacement, read the next line into the pattern space and perform the second replacement.