Вопрос

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?

Это было полезно?

Решение

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

Другие советы

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?

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top