Skip to content

Instantly share code, notes, and snippets.

@ashokarun
Created October 1, 2017 08:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ashokarun/8c6cbae2266dc03a5d600700b0d2d6f5 to your computer and use it in GitHub Desktop.
Save ashokarun/8c6cbae2266dc03a5d600700b0d2d6f5 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
@ashokarun
Copy link
Author

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