Operating System - HP-UX
1819791 Members
3300 Online
109607 Solutions
New Discussion юеВ

SSH: how to perform a remote command with a parameter

 
SOLVED
Go to solution
David_246
Trusted Contributor

SSH: how to perform a remote command with a parameter

Hi,

I make use of ssh since a couple of months.
Now we try to run the following command using ssh :
serverA # ssh -ttt server1 "/sbin/init.d/logsurfer restart"

Now looking at server1 I can see the command comming in :

sh -c /sbin/init.d/logsurfer restart

Now it doesn't work, when I perform this command manualy it also doesn't work as it needs to be quoted :

sh -c "/sbin/init.d/logsurfer restart"

I tried several ways to get ssh report the command quoted to the remote machine, so as one command. Unfortunetly this never worked out. Anyone a suggestion ?


Best Regs David
@yourservice
12 REPLIES 12
Simone Benzi_1
Frequent Advisor

Re: SSH: how to perform a remote command with a parameter

Ciao David,

Try to run:

ssh -ttt server1 "\"/sbin/init.d/logsurfer restart\""

regards,

Simone
David_246
Trusted Contributor

Re: SSH: how to perform a remote command with a parameter

Hi Simone,

Thanks for the input!
Unfortunetly I tried this as well, and please see the result. I can asure you this is the exact command !!

Regs David

# ssh -ttt server1 "\"/sbin/init.d/logsurfer restart\""
sh: /sbin/init.d/logsurfer restart: not found.
Connection to server1 closed.
@yourservice
Simone Benzi_1
Frequent Advisor

Re: SSH: how to perform a remote command with a parameter

Ciao David,

Is it possible for you to try the command with the ksh instead the sh?

Simone
David_246
Trusted Contributor

Re: SSH: how to perform a remote command with a parameter

Nope, not possible.
I can give it a /bin/ksh previous to the command to perform, but it gives me, with or without quotes, the same errors.
Unfortunetly ssh invokes the sh -c on the remote system, so that will not be possible to change.

Any other suggestions? :)

Regs David
@yourservice
Massimo Bianchi
Honored Contributor

Re: SSH: how to perform a remote command with a parameter

Hi,
the "not found" is because with the "" the command is interpreted as a whole command, not a command plus parameteres.

Why do you repeat 3 times the -t (-ttt)?

easy solution, but not nice: create two script that perform
"logsurfer stop" and "logsurfer start"

nicer: tear away the "" :)
ssh -ttt server1 /sbin/init.d/logsurfer restart

it works for me (besides -tt).

Massimo

Steven E. Protter
Exalted Contributor

Re: SSH: how to perform a remote command with a parameter

No itent to hijack.

I've seen a similar problem with ssh though, didn't realize this could be the cause. ssh calls use the Posix Shell?

-t says its to force psuedo terminal allocation.

what about -T to force it not to do that. Your script is a root startup script, it doesn't need a psuedo terminal.

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
David_246
Trusted Contributor

Re: SSH: how to perform a remote command with a parameter

Steve,

I confirm, you must be good. But a restart now works, but I just never get back my prompt :(

So initiating a :

ssh -T server1 "/sbin/init.d/logsurfer restart"

does restart logsurfer, but never gives back my # (prompt). Any ideas.

Regs David
@yourservice
Steven E. Protter
Exalted Contributor

Re: SSH: how to perform a remote command with a parameter

I'd say lucky rather than good.

man page has a few possible options for termination:


~. Disconnect

~^Z Background ssh

~# List forwarded connections


Can't say I know how to implement it. This thread interests me because I have an ssh call core dumping right now and I need to figure out how to get it to use the Korn shell, because the app thats dumping needs that shell.

If this finishes, post back the final resolution.

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
Massimo Bianchi
Honored Contributor
Solution

Re: SSH: how to perform a remote command with a parameter

Try with

ssh -f ...

to send it to background, since you don't need a pty.

Massimo
Steven E. Protter
Exalted Contributor

Re: SSH: how to perform a remote command with a parameter

I think Massimo is right.

ssh -f -T server1 "/sbin/init.d/logsurfer restart"

See what happens.

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
David_246
Trusted Contributor

Re: SSH: how to perform a remote command with a parameter

Ha, solution when perfoming this task in an automated job( so no chance to type interactivly ~. ~& or any other) :

ssh -f -T server1 "/sbin/init.d/logsurfer restart"

So, that's mine. Steve, you still should be able to do the following :

ssh "/bin/ksh "

Maybe this can be your solution.
Thanks for your help in it !! If you have a core file you can send it to me and I'll try to analyze it. Just let me know if you need my help in it.


Regs David
@yourservice
David_246
Trusted Contributor

Re: SSH: how to perform a remote command with a parameter


We were all typing the same solution at the same time, so three people found the same solution. Who is giving me points :)

For al other persons. Case closed, information shareable.

Regs David
@yourservice