0

I have a bash script that runs a few psql commands. Every time a command is ran it prompts for user password. I'd like to make the script input the password automatically so I'd only need to run the script and not need to input anything. I am aware that I can do this for psql

PGPASSWORD=root psql -h localhost -d $db_name -U root -c

but I'd like to know how to automate input in general/

dev-rifaii
  • 217
  • 2
  • 9
  • Does this answers your question? https://stackoverflow.com/questions/6405127/how-do-i-specify-a-password-to-psql-non-interactively – IamK Sep 26 '22 at 08:14

1 Answers1

0

You can export the PGPASSWORD as below:

  1. export PGPASSWORD=root
  2. psql -h localhost -d $db_name -U root -c
Niraj Nandane
  • 1,318
  • 1
  • 13
  • 24