Home > Mobile >  psql command not getting execute in bash file
psql command not getting execute in bash file

Time:01-03

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.

enter image description here

#!/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';"

CodePudding user response:

echo "Starting Database" sudo service postgresql start

After this step.(just switch to postgres)

su - postgres

psql -c "CREATE USER admin WITH PASSWORD 'admin';"

CodePudding user response:

#!/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

# Creating user "admin" with password "admin"
sudo -u postgres psql -c "CREATE USER admin WITH PASSWORD 'admin';"

I fixed the problem by removing sudo -u postgres psql and using sudo -u postgres psql -c "CREATE USER admin WITH PASSWORD 'admin';" Now it's working good

  • Related