代码之家  ›  专栏  ›  技术社区  ›  user3486773

如何保存bash文件中链接的文本?

  •  0
  • user3486773  · 技术社区  · 2 年前

    我正在尝试写一个脚本,自动在我的服务器上创建一个新网站。

    其中一个步骤是转到这个链接并将盐复制到我的wp-config.php文件中:

    https://api.wordpress.org/secret-key/1.1/salt/

    我是bash脚本的新手,希望这很容易做到。

    我不确定是否需要先将其保存为文本,但最终我需要在wp-config.php中替换这一部分:

    define( 'AUTH_KEY',         'put your unique phrase here' );
    define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
    define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
    define( 'NONCE_KEY',        'put your unique phrase here' );
    define( 'AUTH_SALT',        'put your unique phrase here' );
    define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
    define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
    define( 'NONCE_SALT',       'put your unique phrase here' );
    

    以及该链接的结果。

    0 回复  |  直到 2 年前
        1
  •  0
  •   sseLtaH    2 年前

    使用 awk

    $ cp wp-config.php wp-config.bak
    $ curl https://api.wordpress.org/secret-key/1.1/salt/ | awk -F"'" 'NR==FNR {a[$2]=$4;next} {$4=a[$2]}1' OFS="'" - wp-config.php > wp-config.tmp
    $ mv wp-config.tmp wp-config.php
    $ cat wp-config.php
    define( 'AUTH_KEY',         '+koF5XB%cw@d[0-ki.7, L<Jjun`r7U)e]N4T`x` -PgG|MBDjVKqn|v;F f9]?1' );
    define( 'SECURE_AUTH_KEY',  'zk_kt$P|41U-|Vz:r&wfJW=b6D=_?c`=3.`v1n~K~u1-1Qp|]7&4q:8URK+7i)a+' );
    define( 'LOGGED_IN_KEY',    '_R.$kMfRnn6jm#hBN-C04610P.Yg.mxLiaSjH{}9%4c0>/{uiAk+}9oCpfj_<wnJ' );
    define( 'NONCE_KEY',        '40*|=BJN0qo=8O2~x4Rz.A~I+gsF,3UsF?6q/RK5k2;8Dd:o+6o~F&7S_y+^TL-;' );
    define( 'AUTH_SALT',        'irwQFh*=:kyToG= aUF;+K%]$E-]]=^@V[l[7@u-pR;ea*Z+d$&YS]i|<-Gj[Bj^' );
    define( 'SECURE_AUTH_SALT', ',/rVV-JlDv~`R8ocz*`+T^.CQF.`X3+dA?q5MZHVz(8>&H&r:A#XH?/XV>)L :8s' );
    define( 'LOGGED_IN_SALT',   '8zf>mA|rmvH%2C`>acJe?*O-TEJ>f0F&K82)Q4u{T1lOH#kG%IbO5>Vw1Bf9b-98' );
    define( 'NONCE_SALT',       'p,6nSXBfw~4EySqIu!fp):B1ye1Hu{S{V)ef;m9X;/z}/UA/G|I:2|]Awx,K/k+,' );