Reputation: 174
I'm a scripting noob and trying to get this find/replace working that injects salt strings in a wp-config.php file, replacing multiple placeholders.
#!/bin/bash -e
function salt() {
uniqSalt=$(cat /dev/urandom | env LC_CTYPE=C tr -dc "a-zA-Z0-9!@#$%^&*()-_ []{}<>~\`+=,.;:/?|" | fold -w 64 | head -n 1)
echo $uniqSalt
}
perl -pi -e "s/put your unique phrase here/$(salt)/g" wp-config.php
This works, but it only generates the salt once so they are all the same - of course it needs to generate it again for every match.
Is it possible to modify this to do what I want? Or is there a better way?
Thanks.
Upvotes: 2
Views: 94
Reputation: 50637
You don't need bash and unnecessary piping through multiple system utilities,
perl -i -pe'
BEGIN {
@chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
}
s/put your unique phrase here/salt()/ge
' wp-config.php
Upvotes: 2