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
Executing db2 command through ssh
Question
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?
La solution
Autres conseils
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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow