Download and insert salt string inside wordpress wp-config.php with Bash

前端 未结 10 2307
有刺的猬
有刺的猬 2021-02-13 06:27

How can I insert the content of the variable $SALT in a specific point (line or string) of a file like wp-contet.php from wordpress using Bash script?



        
10条回答
  •  孤街浪徒
    2021-02-13 06:39

    If you have csplit available, you can split the original wp-config.php file either side of the salt definitions, download new salts, then cat back together. This keeps the PHP define() statements at the same location in wp-config.php instead of than moving them to a different location within the file:

    # Download new salts
    curl "https://api.wordpress.org/secret-key/1.1/salt/" -o salts
    
    # Split wp-config.php into 3 on the first and last definition statements
    csplit wp-config.php '/AUTH_KEY/' '/NONCE_SALT/+1'
    
    # Recombine the first part, the new salts and the last part
    cat xx00 salts xx02 > wp-config.php
    
    # Tidy up
    rm salts xx00 xx01 xx02
    

提交回复
热议问题