Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MohamedMohsenX2/2fd6ec94061da580de4be774c5d29400 to your computer and use it in GitHub Desktop.
Save MohamedMohsenX2/2fd6ec94061da580de4be774c5d29400 to your computer and use it in GitHub Desktop.
Bulk database user password script
#!/bin/sh
echo "This script is useful for only commonly using CMSs like WP, Joomla, Drupal, Magento, Drupal etc with known configuration location. If nothing listing and you are getting db conntction error check configuration manually.. Thanks by Arunlal"
echo "" > details.txt
echo "Please enter the cPanel username: "
read username
grep -irl ${username}_ /home/$username/*{wp-config,configuration,config,global.inc,db-config,config.properties,configure,mysql.class,Settings}.php /home/$username/*/{wp-config,configuration,config,global.inc,db-config,config.properties,configure,mysql.class,Settings}.php /home/$username/*/*/{wp-config,configuration,config,global.inc,db-config,config.properties,configure,mysql.class,Settings}.php 2>/dev/null grep -v -E "mail|error_log|sql|html|var">> ${username}confs.txt
var=`cat ${username}confs.txt`
if [ -n "$var" ]; then
for i in `cat ${username}confs.txt`; do echo $i >> details.txt; grep -E "DB_USER|user|username|DB_PASSWORD|secret|password" $i |grep -v -E "cookies|generate" >> details.txt; echo "-------" >> details.txt; done
echo " "
echo "***Websites' conf and db details are listed below***"
echo "----------------------------------------------------"
cat details.txt
echo " " > ${username}confs.txt
else
echo "Check the database prefix manually. It seems username and db prefix are not same. Please quit the script. Enter (N/n)!!"
fi
rm -f ${username}confs.txt
read -p "Do you wanna reset the password from here? (y/n)?" choice
case "$choice" in
y|Y ) echo "Alright!! Please give me the following details..."
echo "Enter database username: "
read dbur
echo "Enter current db user password per site's configuration: "
read dbpw
echo "Enter new/same password: "
read dbpwnw
echo "Please wait...... Updating db user $dbur password..."
mysqladmin -u $dbur -p$dbpw password $dbpwnw
echo "Congratulations... DB user password has been updated";;
n|N ) echo "No problem dude.. Reset it from the control panel. Refer https:/www.crybit.com/change-database-user-password-cpanel/";;
* ) echo "Not a valid option.";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment