Created
May 22, 2012 13:36
-
-
Save davidbitton/2769104 to your computer and use it in GitHub Desktop.
Replace a token in a file from a Bash script using Perl
This file contains hidden or 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.