Last active
August 6, 2017 08:55
-
-
Save zevilz/27a6dab1e863d8df7223224e081c4d5f to your computer and use it in GitHub Desktop.
Extract data for connections to db for all WP sites in folder
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 | |
# folder with sites | |
INPUT_DIR='/home/' | |
# path to file for data | |
OUTPUT_FILE='data.txt' | |
find $INPUT_DIR -name 'wp-config.php' > /tmp/files.txt | |
echo -n > $OUTPUT_FILE | |
while read line; do | |
echo "file - $line" >> $OUTPUT_FILE | |
echo -n 'db - ' >> $OUTPUT_FILE | |
grep 'DB_NAME' $line | sed "s/.*DB_NAME.*'\(.*\)'.*/\1/" >> $OUTPUT_FILE | |
echo -n 'user - ' >> $OUTPUT_FILE | |
grep 'DB_USER' $line | sed "s/.*DB_USER.*'\(.*\)'.*/\1/" >> $OUTPUT_FILE | |
echo -n 'password - ' >> $OUTPUT_FILE | |
grep 'DB_PASSWORD' $line | sed "s/.*DB_PASSWORD.*'\(.*\)'.*/\1/" >> $OUTPUT_FILE | |
echo >> $OUTPUT_FILE | |
done < /tmp/files.txt | |
unlink /tmp/files.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment