This may sound like a rather juvenile BASH question, but I'm rather stumped and hope it's something simple to fix. I hope someone has the answer since I don't really have time (swapping out firewalls and half my network is down) to research it.
I have a BASH script that is pretty simple, it backs up postgresQL databases using pg_dump. It runs as root since I am copying data to a SAN and don't really want to configure the postgres user to have access to it. But, in order to get everything dumped properly, I do this:
su postgres - -c <pgdump command>
Now, this has worked perfectly for 3 months now, but the last few days I started getting errors about failed authentication to the databases. Here's where it gets weird. I can su postgres - from a BASH prompt just fine,but when I run the script, it asks me for a password, which it didn't do before. IIRC, I had to change the postgres user from /bin/false to /bin/bash for one of our software devs to be able to monitor the DBs via Jenkins, could that have something to do with it? I can't imagine how, since I can su from the root prompt to the postgres user without asking for a password.
Help!
Mark Haney IT Support Associate/Network Administrator Practichem 10404 Chapel Hill Road Morrisville, NC 27560 W: 919-714-8428
On Mon, 21 Oct 2013, Mark Haney wrote:
This may sound like a rather juvenile BASH question, but I'm rather stumped and hope it's something simple to fix. I hope someone has the answer since I don't really have time (swapping out firewalls and half my network is down) to research it.
I have a BASH script that is pretty simple, it backs up postgresQL databases using pg_dump. It runs as root since I am copying data to a SAN and don't really want to configure the postgres user to have access to it. But, in order to get everything dumped properly, I do this:
su postgres - -c <pgdump command>
Now, this has worked perfectly for 3 months now, but the last few days I started getting errors about failed authentication to the databases. Here's where it gets weird. I can su postgres - from a BASH prompt just fine,but when I run the script, it asks me for a password, which it didn't do before. IIRC, I had to change the postgres user from /bin/false to /bin/bash for one of our software devs to be able to monitor the DBs via Jenkins, could that have something to do with it? I can't imagine how, since I can su from the root prompt to the postgres user without asking for a password.
Help!
Is it asking for root password or postgres password?
billo
Is it asking for root password or postgres password?
As I'm running the script as root, it's almost certainly asking for thepostgres user password.
On Mon, 21 Oct 2013, Mark Haney wrote:
Is it asking for root password or postgres password?
As I'm running the script as root, it's almost certainly asking for thepostgres user password.
Heh. You'd think so. But, I've managed to inadvertently su to some user in a script and then run a subordinate script that required root password...
Sigh. If there's a way to screw up, I've figured out how to do it at least once.
billo
On Mon, 21 Oct 2013, Mark Haney wrote:
This may sound like a rather juvenile BASH question, but I'm rather stumped and hope it's something simple to fix. I hope someone has the answer since I don't really have time (swapping out firewalls and half my network is down) to research it.
I have a BASH script that is pretty simple, it backs up postgresQL databases using pg_dump. It runs as root since I am copying data to a SAN and don't really want to configure the postgres user to have access to it. But, in order to get everything dumped properly, I do this:
su postgres - -c <pgdump command>
Now, this has worked perfectly for 3 months now, but the last few days I started getting errors about failed authentication to the databases. Here's where it gets weird. I can su postgres - from a BASH prompt just fine,but when I run the script, it asks me for a password, which it didn't do before. IIRC, I had to change the postgres user from /bin/false to /bin/bash for one of our software devs to be able to monitor the DBs via Jenkins, could that have something to do with it? I can't imagine how, since I can su from the root prompt to the postgres user without asking for a password.
Help!
It's been awhile since I used postgres, having moved to mysql, but if it's asking for the postgres admin password rather than root password, can't you get around it by putting it in a file somewhere like .pgpass or setting an environment variable like PGPASSWORD? Maybe you need to set that in the shell you are created. See: http://www.postgresql.org/docs/9.1/static/libpq-envars.html and http://stackoverflow.com/questions/6523019/postgresql-scripting-psql-executi...
billo
su postgres - -c <pgdump command>
Now, this has worked perfectly for 3 months now, but the last few days I started getting errors about failed authentication to the databases. Here's where it gets weird. I can su postgres - from a BASH prompt just fine,but when I run the script, it asks me for a password, which it didn't do before. IIRC, I had to change the postgres user from /bin/false to /bin/bash for one of our software devs to be able to monitor the DBs via Jenkins, could that have something to do with it? I can't imagine how, since I can su from the root prompt to the postgres user without asking for a password.
It's been awhile since I used postgres, having moved to mysql, but if it's asking for the postgres admin password rather than root password, can't you get around it by putting it in a file somewhere like .pgpass or setting an environment variable like PGPASSWORD? Maybe you need to set that in the shell you are created. See: http://www.postgresql.org/docs/9.1/static/libpq-envars.html and http://stackoverflow.com/questions/6523019/postgresql-scripting-psql-executi...
My problem is this, if it works as root from a bash prompt, why /won't/ it work as root from a bash script? Shoudn't it ask for the password in both instances?
On Mon, 21 Oct 2013, Mark Haney wrote:
My problem is this, if it works as root from a bash prompt, why /won't/ it work as root from a bash script? Shoudn't it ask for the password in both instances?
Yeah, you'd think so. When stuff like that happens to me, it's often that the environments are different -- I sometimes have things in my .profile or .bash_profile file that are not in my .bashrc file, so subshells are a bit different than the original shell. Thus, for instance, it is conceiveable that there's a PBPASSWORD variable set in your .profile that isn't set in .bashrc, or something like that.
billo
My problem is this, if it works as root from a bash prompt, why /won't/ it work as root from a bash script? Shoudn't it ask for the password in both instances?
Yeah, you'd think so. When stuff like that happens to me, it's often that the environments are different -- I sometimes have things in my .profile or .bash_profile file that are not in my .bashrc file, so subshells are a bit different than the original shell. Thus, for instance, it is conceiveable that there's a PBPASSWORD variable set in your .profile that isn't set in .bashrc, or something like that.
I will definitely have to look at that. It has to be something like this since it was working until I had to mess with the setup to allow our devs to monitor the DB and backups from Jenkins. Thanks for the help.
On Mon, 21 Oct 2013, Mark Haney wrote:
I will definitely have to look at that. It has to be something like this since it was working until I had to mess with the setup to allow our devs to monitor the DB and backups from Jenkins. Thanks for the help.
Don't forget to check your system profile file as well.
billo
On 10/21/2013 05:50 AM, Mark Haney wrote:
Now, this has worked perfectly for 3 months now, but the last few days I started getting errors about failed authentication to the databases. Here's where it gets weird. I can su postgres - from a BASH prompt just fine,but when I run the script, it asks me for a password, which it didn't do before.
Someone probably changed or removed the "ident" authentication for localhost in pg_hba.conf. Start there. The default configuration is:
# "local" is for Unix domain socket connections only local all all ident # IPv4 local connections: host all all 127.0.0.1/32 ident # IPv6 local connections: host all all ::1/128 ident
If you don't think that's the case, post the output of the script so that we can tell what's prompting you.