Created
November 2, 2012 19:53
-
-
Save mariusbutuc/4003944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Argument = -e email -u username -i initials -v | |
usage() | |
{ | |
cat << EOF | |
usage: $0 options | |
This script creates a new dev/test user on imcloud-devtest.torolab.ibm.com. | |
This script will setup the OS user, and create both the API, and IMC | |
databases for the user. Finally this script sends a confirmation email | |
to the newly added user. | |
OPTIONS: | |
-h Show this message | |
-e Email address | |
-u Username (8 characters max) | |
-i Initials | |
-v Verbose | |
EOF | |
} | |
email= | |
username= | |
initials= | |
VERBOSE= | |
while getopts .he:u:i:v. OPTION | |
do | |
case $OPTION in | |
h) | |
usage | |
exit 1 | |
;; | |
e) | |
email=$OPTARG | |
;; | |
u) | |
username=$OPTARG | |
;; | |
i) | |
initials=$OPTARG | |
;; | |
v) | |
VERBOSE=1 | |
;; | |
?) | |
usage | |
exit | |
;; | |
esac | |
done | |
if [[ -z $email ]] || [[ -z $username ]] || [[ -z $initials ]] | |
then | |
usage | |
exit 1 | |
fi | |
echo "Email: $email" | |
echo "Username: $username" | |
echo "Initials: $initials" | |
# Add user | |
useradd -G db2iadm1 $username | |
echo "P@s5w0rd | |
P@s5w0rd" | passwd $username | |
chage -d 0 $username | |
echo "source /home/db2inst1/sqllib/db2profile" >> /home/$username/.bashrc | |
# Create databases | |
imc_db_name="IMC_$initials" | |
api_db_name="API_$initials" | |
echo "db2 create db $imc_db_name" > /tmp/createuserdbs.sh | |
echo "db2 create db $api_db_name" >> /tmp/createuserdbs.sh | |
chmod +x /tmp/createuserdbs.sh | |
su - db2inst1 -c "/tmp/createuserdbs.sh" | |
#rm /tmp/createuserdbs.sh | |
echo "db2 connect to $imc_db_name" > /tmp/adduser.sh | |
echo "db2 grant dbadm on database to user $username with dataaccess with accessctrl" >> /tmp/adduser.sh | |
# Marius | |
# [db2inst1@imcloud-devtestdb ~]$ db2 grant dbadm on database to user marius with dataaccess with accessctrl | |
# DB21034E The command was processed as an SQL statement because it was not a | |
# valid Command Line Processor command. During SQL processing it returned: | |
# SQL0104N An unexpected token "dataaccess with accessctrl" was found following | |
# "to user marius with". Expected tokens may include: "<space>". | |
# SQLSTATE=42601 | |
echo "db2 revoke connect on database from public" >> /tmp/adduser.sh | |
# Marius: | |
# [db2inst1@imcloud-devtestdb ~]$ db2 revoke connect on database from public | |
# DB21034E The command was processed as an SQL statement because it was not a | |
# valid Command Line Processor command. During SQL processing it returned: | |
# SQL0556N An attempt to revoke a privilege, security label, exemption, or role | |
# from "PUBLIC" was denied because "PUBLIC" does not hold this privilege, | |
# security label, exemption, or role. SQLSTATE=42504 | |
echo "db2 connect reset" >> /tmp/adduser.sh | |
echo "db2 connect to $api_db_name" >> /tmp/adduser.sh | |
echo "db2 grant dbadm on database to user $username with dataaccess with accessctrl" >> /tmp/adduser.sh | |
echo "db2 revoke connect on database from public" >> /tmp/adduser.sh | |
echo "db2 connect reset" >> /tmp/adduser.sh | |
chmod +x /tmp/adduser.sh | |
su - db2inst1 -c "/tmp/adduser.sh" | |
#rm /tmp/adduser.sh | |
# Send confirmation Email to user | |
message="You have just been added to the IM Demo Cloud dev/test DB2 server. | |
Your credentials are as follows: | |
* Hostname: imcloud-devtestdb.torolab.ibm.com | |
* Username: $username | |
* Password: P@s5w0rd (you must change this on initial login) | |
* DB2 port number: 50001 | |
* IMCloud Database (for intranet site): $imc_db_name | |
* IMCloudAPI Database (for internet site): $api_db_name | |
*Important* To change your password follow the instructions at: | |
https://w3-connections.ibm.com/wikis/home?lang=en_US#/wiki/IM%20Demo%20Cloud%20Credentials/page/Logging%20in%20and%20Managing%20Servers | |
To catalog your databases you can issue the following db2 commands: | |
> db2 catalog tcpip node imc_dev remote imcloud-devtestdb.torolab.ibm.com server 50001 | |
> db2 catalog database $imc_db_name as $imc_db_name at node imc_dev authentication server | |
> db2 catalog database $api_db_name as $api_db_name at node imc_dev authentication server | |
> db2 catalog tcpip node imc_dev remote imcloud-devtestdb.torolab.ibm.com server 50001 | |
> db2 catalog database imc_mgb as imc_mgb at node imc_dev authentication server | |
> db2 catalog database api_mgb as api_mgb at node imc_dev authentication server | |
To connect to your databases using the CLP, you can issue the following command: | |
> db2 connect to $imc_db_name user $username | |
- imdemocloud" | |
echo $message | |
python send.py "$email" "You have been added to the Dev/Test IMCloud environment" "$message" | |
exit 0 | |
# Marius: | |
# [IMCloud (feature_improve_ux_performance)]$ bundle exec rake --trace db:migrate | |
# [...] | |
# == DropLegacyInfoserverPot: migrating ======================================== | |
# rake aborted! | |
# An error has occurred, this and all later migrations canceled: | |
# RuntimeError: Failed to execute statement due to: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "LIMIT" was found following "". Expected tokens may include: "FETCH FIRST <n> ROWS ONLY". SQLSTATE=42601 SQLCODE=-104: SELECT offerings.* FROM offerings WHERE offerings.identifier = 'infoserver_pot_0001' LIMIT 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment