Skip to content

Instantly share code, notes, and snippets.

@davidbitton
Created May 22, 2012 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidbitton/2769104 to your computer and use it in GitHub Desktop.
Save davidbitton/2769104 to your computer and use it in GitHub Desktop.
Replace a token in a file from a Bash script using Perl
#!/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
@davidbitton
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment