#!/bin/sh random_pass() { PASS_LEN=`perl -le 'print int(rand(6))+9'` START_LEN=`perl -le 'print int(rand(8))+1'` END_LEN=$(expr ${PASS_LEN} - ${START_LEN}) SPECIAL_CHAR=`perl -le 'print map { (qw{@ ^ _ -})[rand 6] } 1'`; NUMERIC_CHAR=`perl -le 'print int(rand(10))'`; PASS_START=`perl -le "print map+(A..Z,a..z,0..9)[rand 62],0..$START_LEN"`; PASS_END=`perl -le "print map+(A..Z,a..z,0..9)[rand 62],0..$END_LEN"`; PASS=${PASS_START}${SPECIAL_CHAR}${NUMERIC_CHAR}${PASS_END} echo $PASS } #backup cp /usr/local/directadmin/scripts/setup.txt /usr/local/directadmin/scripts/setup.txt.bak cp /usr/local/directadmin/conf/my.cnf /usr/local/directadmin/conf/my.cnf.bak cp /usr/local/directadmin/conf/mysql.conf /usr/local/directadmin/conf/mysql.conf.bak #ResetPWD source /usr/local/directadmin/conf/mysql.conf MYSQLOLD=$passwd MYSQLNEW=`random_pass` echo "OLDPASS:"$MYSQLOLD echo "NEWPASS:"$MYSQLNEW chmod 644 /usr/local/directadmin/conf/mysql.conf perl -pi -e "s/^mysql=.*$/mysql=$MYSQLNEW/" /usr/local/directadmin/scripts/setup.txt perl -pi -e "s/^password=.*$/password=$MYSQLNEW/" /usr/local/directadmin/conf/my.cnf perl -pi -e "s/^passwd=.*$/passwd=$MYSQLNEW/" /usr/local/directadmin/conf/mysql.conf mysqladmin -uroot -p$MYSQLOLD password $MYSQLNEW mysqladmin -uda_admin -p$MYSQLOLD password $MYSQLNEW service directadmin restart