I am trying to write a script that automatically makes a new website on my server.
one of the steps is to go to this link and copy the salts into my wp-config.php file:
https://api.wordpress.org/secret-key/1.1/salt/
I’m new to bash script and hoping this would be easy to do.
I’m not sure if I need to save it as a text first, but ultimately I need to replace this part in my 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' );
with the results from that link.
Advertisement
Answer
Using 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+,' );