Replace a token in a file from a Bash script using Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
perl - /var/www/html/wp-config.php <<'EOF' | |
use strict; | |
use warnings; | |
$^I = '.bak'; | |
my $keys = `curl -sS https://api.wordpress.org/secret-key/1.1/salt/`; | |
while(<>) { | |
if (/\{KEYS_TOKEN\}/){ | |
print $keys; | |
} else { | |
print; | |
} | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet is derived from a larger Bash script used in an Amazon AWS CloudFormation template. The idea is that earlier in the template, the WordPress wp-config.php file is created with "{KEYS_TOKEN}" in the middle. The actual keys must be injected into the middle of the file, and not appended to the end. This code accomplishes that.