사용자 계정 + mysql 계정 추가 스크립트사용자 계정 + mysql 계정 추가 스크립트

Posted at 2010. 10. 5. 12:59 | Posted in Server
반응형

사용자 계정 + mysql 계정 추가 스크립트

사용자 계정 추가 쉘 스크립트

사용법 => /root/script/newuser 사용자ID
vi /root/script/newuser
------------------------------------------------------------------------------
#!/bin/bash
clear

echo ==================================================================
echo "                     UserAdd Process Start                      "
echo ==================================================================

echo -n "User Name : "
read username
useradd $username
echo ------------------------
echo PassWord Setting
echo ------------------------
passwd $username

echo ==================================================================
echo "                     www root directory making                      "
echo ==================================================================
echo
echo -n "www root Directory path : "
echo /home/$username/public_html
mkdir -p /home/$username/public_html

echo ==================================================================
echo "             root directory setting & test index.php making     "
echo ==================================================================

chmod 775 /home/$username
chmod 775 /home/$username/public_html
chown $username.$username /home/$username/public_html

echo " " >>/home/$username/public_html/index.php
echo "<? phpinfo(); ?>" >> /home/$username/public_html/index.php

chown $username.$username /home/$username/public_html/index.php
chmod 775 /home/$username/public_html/index.php

echo checking -----------------------------------------------------------

ls -al /home/$username

echo checking -----------------------------------------------------------

ls -al /home/$username/public_html

echo ==================================================================
echo "                        MySQL useradd"
echo ==================================================================
echo "Username : $username"
echo "dbname : $username"
echo -n "User p/w : "

read userpw

echo " " >> mysql_useradd.sql
echo "use mysql" >> mysql_useradd.sql
echo "create database $username;" >> mysql_useradd.sql
echo "insert into user (host, user, password) values ('localhost', '$username', password('$userpw'));" >> mysql_useradd.sql
echo "insert into db values ('localhost', '$username', '$username', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y');" >> mysql_useradd.sql
echo "FLUSH PRIVILEGES;" >> mysql_useradd.sql

/usr/local/mysql/bin/mysql -uroot -p97081056 < ./mysql_useradd.sql

cat ./mysql_useradd.sql
rm -rf ./mysql_useradd.sql

반응형

//