Skip to content

Commit

Permalink
Merge pull request #3 from Nortindev/main
Browse files Browse the repository at this point in the history
added function 14 to scan database names
  • Loading branch information
brmb authored Mar 17, 2023
2 parents 58abbac + 72fc2d4 commit 8c63fde
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function main {
echo -e "11)${BGREEN} Flush Elementor cache${NC} - flushes WordPress Elementor cache."
echo -e "12)${BGREEN} Flush LiteSpeed cache${NC} - flushes WordPress LiteSpeed cache."
echo -e "13)${BGREEN} Test PHP mail${NC} - allows to test PHP mail easier."
echo -e "14)${BGREEN} Scan and print databases${NC} - allows to see which databases belong to all domain/subdomain in WP sites."
echo -e "0)${BRED} Exit${NC} - exits the script."

while true; do
Expand All @@ -50,6 +51,7 @@ function main {
11) SELECT=func_elementors;;
12) SELECT=func_litespeeds;;
13) SELECT=func_php_mails;;
14) SELECT=func_scan_databases;;
0) SELECT=exit;;
*) echo -e "${BRED}Invalid selection, try again.${NC}"; continue
esac
Expand Down Expand Up @@ -823,6 +825,42 @@ function func_php_mail_subdomain {
return 1
}

function func_scan_databases() {
greenText() {
echo -e "The domain (\033[32m$1\033[0m) has this DB_NAME (\033[32m$2\033[0m)"
}

echo "Select an option:"
echo "1. Main domains"
echo "2. Subdomains"
read option

if [ "$option" == "1" ]; then
for domain in $(ls /home/"$USER"/domains); do
echo "Checking domain: $domain"
wp_config="/home/$USER/domains/$domain/public_html/wp-config.php"
if [ -f "$wp_config" ]; then
db_name=$(awk -F "'" '/DB_NAME/ {print $4}' "$wp_config")
greenText "$domain" "$db_name"
fi
done
elif [ "$option" == "2" ]; then
echo "Enter main domain name:"
read main_domain
for subdomain in $(find /home/"$USER"/domains/"$main_domain"/public_html -maxdepth 1 -type d | tail -n +2); do
wp_config="$subdomain/wp-config.php"
if [ -f "$wp_config" ]; then
db_name=$(awk -F "'" '/DB_NAME/ {print $4}' "$wp_config")
subdomain_name=$(echo "$subdomain" | awk -F/ '{print $NF}')
greenText "$subdomain_name.$main_domain" "$db_name"
fi
done
else
echo "Usage: check_db_names [1|2]"
fi
return 1
}

main

while test $? -eq 0; do
Expand Down

0 comments on commit 8c63fde

Please sign in to comment.