doufu7464 2017-09-15 12:05
浏览 115
已采纳

Sed更换令牌的问题

I have a bit of bash that I use to "install" a wordpress site on a server.

In it, I do a curl request to get the randomized SALTs via SALTS=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/);

And I put a "token" in my wp-config.php file ##WP_SALTS##

It seems that my sed statement is not proper, as it keeps throwing me an error:

sed: -e expression #1, char 99: unknown option to `s'

I have tried:

sed -i "s+##WP_SALTS##+$SALTS+g" $WPCONFIG

As well:

sed -i "s/##WP_SALTS##/$SALTS/g" $WPCONFIG

Still the error presents. What am I doing wrong?

the response from the curl request are random each time, but are similar to:

define('AUTH_KEY', ':a>?5od_kaveFKaIB8px|!vgF-W/6/AQX04=&>Tu.-q3ehGOh59=SX+qc9sWk|gG'); define('SECURE_AUTH_KEY', ':tw+w! Sn2n~Rt0ReVA6#eWqsUXW5elHo@V~ oiRhTH4k]kg{<k`:An`]z==K@wZ'); define('LOGGED_IN_KEY', 'mD,JT*4pa3}zfGEpXFR}9jlzF,iD ;:]|>yu]T}&8Uy~(-5ml/AEBTG4|7QYCB|j'); define('NONCE_KEY', '@{Q`.7T a)S?0DTutE}D5Is(UlwnG4NuoQiFHas&i@qz%-HTd7-8[v50Nx<]akuT'); define('AUTH_SALT', 'es*7hCVnh/+c-cecgmZ?%QZ_KN^kaA[jD]N}{A8sK|~MH@Vl|(6-|{3EIGMhksy['); define('SECURE_AUTH_SALT', '}AF@:i!hy#C5,Q_5c4yhycm~i|fc53@+|h7r5H9y(/&4VBeX&sOrKC-6+AqeZ|L>'); define('LOGGED_IN_SALT', '4,}H+&[@qN#^!B+?3a+Mh0+?pURhP|v.CV/]4F-6G!TncU*Pd=GMSRPf?58j5Sv0'); define('NONCE_SALT', 'Dlo,7F[:EaWQT57-P0Q+x</nUf4UD&LH=-0wS6l._2Fx!-jR0KBJ-U_1*{sXo?>Q');

EDIT Now implementing a way to randomly generate the 64 character salts with the following:

RSTR=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-64} | head -n 1);
SALTS="define('AUTH_KEY', '$RSTR');
define('SECURE_AUTH_KEY', '$RSTR');
define('LOGGED_IN_KEY', '$RSTR');
define('NONCE_KEY', '$RSTR');
define('AUTH_SALT', '$RSTR');
define('SECURE_AUTH_SALT', '$RSTR');
define('LOGGED_IN_SALT', '$RSTR');
define('NONCE_SALT', '$RSTR');";
sed -i "s/##WP_SALTS##/$SALTS/g" $WPCONFIG

I've replaced the delimiter with +, ~, /, &, * and they all still generate this same error.

  • 写回答

3条回答 默认 最新

  • douwen3127 2017-09-15 12:30
    关注

    If SALTS may contain any character it can be done with perl.

    Passing by environment :

    SALTS="$SALTS" perl -i.bak -pe 's/##WP_SALTS##/$ENV{SALTS}/g' "$WPCONFIG"
    

    Passing by arguments :

    perl -i.bak -pe 'BEGIN{$salts=shift}s/##WP_SALTS##/$salts/g' "$SALTS" "$WPCONFIG"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀