0

trying to ssh to another system then perform db2 commands however using 'su db2admin -c' does not seem to work, although it works for normal system commands ..

#!/bin/bash

sshpass -p 'passw0rd' ssh root@server.com "su db2admin -c 'db2text start'"

this is the output ..

rob@laptop:~/Desktop$ ./script.sh
bash: db2text: command not found

Any ideas?

bobbyrne01
  • 6,295
  • 19
  • 80
  • 150

3 Answers3

0

I'll hazard a guess and say that root doesn't have any of the db2 stuff in hi path. And since you're using su db2admin rather than su - db2admin db2admin inherits root's environment. Try with that extra - thrown in.

That all said: why on earth aren't you connecting w/ passwordless keys as db2admin?

tink
  • 14,342
  • 4
  • 46
  • 50
0

The PATH is not getting updated to the normal root users PATH. Either specify the full path to db2text or add a dash (-) before the username to reload the environment variables

Eric
  • 2,056
  • 13
  • 11
0

Another solution that worked ..

#!/bin/bash

sshpass -p 'passw0rd' ssh root@server.com "su db2admin -c '~/sqllib/bin/db2text start'"

But problem is db2 path may change, better to use Eric's answer.

bobbyrne01
  • 6,295
  • 19
  • 80
  • 150