1748121 Members
3297 Online
108758 Solutions
New Discussion юеВ

Re: Query About SSH

 
SOLVED
Go to solution
shameemsoft
Frequent Advisor

Query About SSH

Dear,

We need to execute one command from remote host to stop one service. Already SSH key has configured. I tried with below command. Able to connect the host But the command is not executed.

ssh -t hostname su - username
-c "/usr/sap/DAA/SYS/exe/uc/hpia64/sapcontrol
-nr 24 -function StopService"

When I run this command locally, it is working.

Help me on this to resolve this issue.

Regards
Shameem
9 REPLIES 9

Re: Query About SSH

i think when u do su - username , u open another shell and this script stops functioning .

if you want to run command as the user "username" , you could try ssh username@hostname and then run the command .
However, the previously configured ssh keys will not work here ,as this is a different user.
shameemsoft
Frequent Advisor

Re: Query About SSH

Thanks Amit for your response.

But I need to login as root first then only i need to login as normal user to execute the command. Because SSH Key is configured only for root account & should not be for normal user in our environment.

Is there any possibilities?

Regards
Shameem
shameemsoft
Frequent Advisor

Re: Query About SSH

I forgot to add one more information. I tried different command using same syntax. it is working..

I checked the command which is not working properly. command syntax is correct. i dont know why it is not working.

Regards
Shameem
Hakki Aydin Ucar
Honored Contributor

Re: Query About SSH

in generally locally working means that different environment variables , solution use absolute path rather than relative path.
As far as I can see already used full path, so be sure your remote server can accept the above command locally ?
Steven E. Protter
Exalted Contributor
Solution

Re: Query About SSH

Shalom,

do a straight login to the the remote server.

ll usr/sap/DAA/SYS/exe/uc/hpia64/sapcontrol

You are using the full path of the command. That should negate any environment problems.

You are also doing an su - username

These steps need to be tested individually to know which part is failing.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Doug O'Leary
Honored Contributor

Re: Query About SSH

Hey;

As others have mentioned, enabling the keys to log into the correct user the first time instead of su'ing into it is the cleaner approach.

If, for whatever reason (probably political) that's not practical, create a script that contains that line:

#!/bin/ksh

. /root/.profile # or where ever root's profile is

su - ${user} -c "/usr/sap/DAA/SYS/exe/uc/hpia64/sapcontrol
-nr 24 -function StopService"
# eof

then call the script from the ssh command:

ssh -t ${host} /root/bin/sapcontrol

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
dirk dierickx
Honored Contributor

Re: Query About SSH

try with adding the '-t' option to your ssh command.
shameemsoft
Frequent Advisor

Re: Query About SSH

Thank you for your response.

I tried to login directly without su as per Mr. Steven. It is working fine

ssh -t username@juepp04 "/usr/sap/DAA/SYS/exe/uc/hpia64/sapcontrol -nr 24 -function StopService"

It is failed when I use su on this command. But it is working(with su) when I start the service :). Any specific reason for this?

Also I have created script separately as per
Mr. Doug, it is working fine.

One more information, i need to run this command from cluster package. separate script is ok? or anything needs to be done ?

Regards
Shameem

Doug O'Leary
Honored Contributor

Re: Query About SSH

Hey;

As long as the separate script is either in a relocatable filesystem or in the same place on both systems if using a local filesystem, you can run it from the package control script w/o issue.

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html