[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [TEKNIK] Automatisk fremstilling af MySQL Databaser som root i BASH



On 04/18/2011 08:02 AM, Martin Møller Skarbiniks Pedersen wrote:
On Monday, 18 April 2011, Thomas Rosendal Jensen<sslug@sslug>

Nu har gjort noget du godt vil bryde dig om.
Jeg har bestilt følgende bog fra eLounge.dk :)

Vare nr Titel Antal Pris Total Beløb
0596526784 bash Cookbook 1 310,94 310,94


Det er en rigtig god bog, som jeg også anvender, når jeg underviser i
Shell scripting.

Hilsen
/martin

Så er der mere kode.
Det kan anbefales at bruge en Debian 6.0.1a eller nyere, kørende virtual machine til at teste koden med.

#!/bin/bash
set -x
#
ROOTPASSWD='sencur'
MNDOMN='juac.dk'
MNDOMNUNDERSCORE='Juac_dk'
IP=90.184.106.85
#
#for USRNME in /home/*
USRARRAY=$(ls -l --format=single-column /home/)
for USRNME in sslug@sslug
do
 DIR="/home/${USRNME}/PUBLIC_HTML"
 if [ ! -d ${DIR} ];
 then
  mkdir ${DIR}
 fi
 if [ ! -e /home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt ];
 then
 DBPASSWD=`mkpasswd qwerty`
mysql -uroot -p${ROOTPASSWD} << EOT
create user \'$USRNME\' identified by \'${DBPASSWD}\';
grant all privileges on \'$UNDERSCORENAME\'.* to \'$USRNME \'@\'localhost\';
exit;
EOT
echo "The username of the databases is ${USRNME}. And the password for the databases is ${DBPASSWD}" > "/home/${USRNME}/PUBLIC_HTML/your_databases.txt"
 echo ${DBPASSWD} > "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt"
 fi
#
# for USRDOMN in /home/${USRNME}/PUBLIC_HTML/*
 USRDOMNARRAY=$(ls -l --format=single-column /home/${USRNME}/PUBLIC_HTML/)
 for USRDOMN in sslug@sslug
 do
  LNK=${USRDOMN}.${USRNME}.${MNDOMN}
  UNDERSCORENAME=${USRDOMN}_${USRNME}_${MNDOMNUNDERSCORE}
  echo "USRDOMN:"${USRDOMN}
  echo "USRNME:"${USRNME}
if [ ! -e /home/${USRNME}/PUBLIC_HTML/${USRDOMN}.reserved -a -d /home/${USRNME}/PUBLIC_HTML/${USRDOMN} ];
   then	
   mkdir "/usr/lib/cgi-bin/${UNDERSCORENAME}"	
   echo "<VirtualHost *:80>
 ServerAdmin sslug@sslug
 ServerName www.${LNK}
 ServerAlias ${LNK}
 DocumentRoot ${DIR}/${USRDOMN}
  # Set Document Root directory options
  <Directory />
    Options FollowSymlinks -Indexes Includes
    # Allow use of .htaccess file
    AllowOverride Limit FileInfo
  </Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/${UNDERSCORENAME}
  # Set CGI-BIN directory options
  <Directory /cgi-bin>
    AllowOverride None
    Options +ExecCGI -Multiviews +SymlnksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>
 CustomLog /var/log/apache2/access.log common
 ErrorLog /var/log/apache2/error.log
</VirtualHost>" > "/etc/apache2/sites-available/${UNDERSCORENAME}"
  /usr/sbin/a2ensite ${UNDERSCORENAME}
  echo "${IP} WWW.${LNK} ${LNK}" >> /etc/hosts
  #/etc/init.d/apache2 stop
  #/etc/init.d/apache2 start
  #/usr/sbin/apache2ctl configtest &&
  #/usr/sbin/apache2ctl graceful
  /etc/init.d/apache2 reload
  #DBPASSWD=`mkpasswd qwerty`
mysqladmin create ${UNDERSCORENAME} -u${USRNME} -p< "/home/${USRNME}/PUBLIC_HTML/DB_USER_PASSWD.txt" #echo "The username of the database ${UNDERSCORENAME} is ${USRNME}. And the password for the database is ${DBPASSWD}" > "${DIR}/${LNK}.txt"
  touch /home/${USRNME}/PUBLIC_HTML/${USRDOMN}.reserved
  fi
 done
done



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2011-05-01, 02:01 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *