2
1
I am trying to create a script that logs as a different user to create a database backup.
So far I have encountered a few problems, such as having to input sudo
password, or not being able to bypass the password prompt for the PostgreSQL database credentials.
My script does the following:
#!/bin/bash
sudo su - postgres
cd /opt/app/backup
pg_dump --username=admin dbName > file.gz
When I run this script, it changes my local user to the postgres
user as expected, but it does not execute the other lines until I type in logout
. The prompt becomes stuck on:
-bash-4.1$
Any help would be greatly appreciated. I am using RedHat.