user705142
user705142

Reputation: 461

SSH command in a bash script isn't run when the script is executed by an application

I'm using PG pool, which executes a failover script when a database node goes down. The script needs to touch a certain file on the new master and make some changes on the old master. It works fine when I run it, but it doesn't when run by the application. I know the script is being executed appropriately as it sends me an email with the host details. Keys are set-up so passwords aren't required.

The script is as follows:

#! /bin/sh

OLD_HOST=$1
NEW_HOST=$2

# new host: touch trigger file
/usr/bin/ssh -T root@$NEW_HOST /bin/touch /mirror/pg_trigger/trigger

# old host: remove trigger file
/usr/bin/ssh -T root@$OLD_HOST /bin/rm /mirror/pg_trigger/trigger -f

# old host: rename recovery.done to recovery.conf
/usr/bin/ssh -T root@$OLD_HOST /bin/mv /opt/postgres/9.1/data/recovery.done /opt/postgres /9.1/data/recovery.conf -f

It doesn't even work if the old/new host is the local machine. I have a feeling this has to do with it being run via the pgpool user, but I'm really not sure. Any ideas?

Upvotes: 0

Views: 461

Answers (1)

Sionide21
Sionide21

Reputation: 2211

When you run it manually, do you run as the pgpool user? SSH keys are per user so if you are running as a different account, you will get different results.

You could also try the -i <keypath> flag with SSH to explicitly pass the path to your key.

Upvotes: 2

Related Questions