Last active
September 18, 2019 12:58
-
-
Save jacekkopecky/6c13a4f6a362c03cfc64c68d19f91d28 to your computer and use it in GitHub Desktop.
create postgres user and database based on hostname – used in OneServerPerStudent at Uni of Portsmouth
This file contains 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/sh | |
echo creating PostgreSQL user and database for the main user of this machine | |
# wait for postgres to start | |
while ! su -c "echo testing postgres connection; psql -c '\\c'" postgres | |
do | |
echo waiting for postgres to start | |
sleep 10 | |
done | |
# check hostname again in case it wasn't ready when the script started | |
host='"'`hostname`'"' | |
echo "creating PostgreSQL user and database for $host - ignore following issues in case the user already exists" | |
su -c "psql -c 'create user $host superuser login password '\'root\'" postgres | |
su -c "psql -c 'create database $host owner $host'" postgres |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use like this:
then it wants to be tested at osps-devel