I have following code in my bash script to install golang and psql server, I wanted to create a user with username "admin" and password "admin". After running the script, it will entered into psql server but psql -c "CREATE USER admin WITH PASSWORD 'admin';"
doesn’t get execute.
#!/bin/bash
# Install golang
echo "Installing required package"
sudo apt-get update
sudo apt install snapd
snap install go --classic
# Install postgreSQL
echo "Installing postgreSQL"
sudo apt-get update
sudo apt install postgresql postgresql-contrib postgresql-client
# Starting database
echo "Starting Database"
sudo service postgresql start
sudo -u postgres psql
# Creating user "admin" with password "admin"
echo "Creating user 'admin' with password 'admin'"
psql -c "CREATE USER admin WITH PASSWORD 'admin';"
2
Answers
I fixed the problem by removing
sudo -u postgres psql
and usingsudo -u postgres psql -c "CREATE USER admin WITH PASSWORD 'admin';"
Now it's working goodecho "Starting Database"
sudo service postgresql start
After this step.(just switch to postgres)
su – postgres
psql -c "CREATE USER admin WITH PASSWORD ‘admin’;"