Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to run sudo -u wwwrun sh -c 'svn status -uq /srv/www/htdocs/loquat' over ssh. When using one ssh it works smoothly. Now there is one server that needs to be connected through another server via ssh.

If I issue

sudo ssh -t root@pacific ssh root@loquat "sudo -u wwwrun sh -c 'svn status -uq /srv/www/htdocs/loquat'" 2>&1

I get Type 'svn help' for usage.

But when I do sudo ssh -t root@pacific ssh root@loquat I am connected to the desired server and then running sudo -u wwwrun sh -c 'svn status -uq /srv/www/htdocs/loquat manually gives me correct output.

And when I run sudo ssh -t root@pacific ssh root@loquat "sudo -u wwwrun sh -c 'id'" 2>&1 I get correctly uid=30(wwwrun) gid=8(www) groups=8(www),1001(eduserver)

What do I need to do to fix that?

  • OpenSSH_5.1p1, OpenSSL 0.9.8j-fips 07 Jan 2009
  • SuSE 10.2
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try this:

sudo ssh root@pacific ssh root@loquat sudo -u wwwrun svn status -uq /srv/www/htdocs/loquat 2>&1
share|improve this answer
    
Works, could you explain? –  Radek Sep 27 '12 at 3:07
1  
The bash removes quotes when interpreting a command. So when you 'nesting' commands over a long chain of sudo's ssh's and sh's the final command looks not as you expect. Also I removed unnecessary 'sh -c' as it only complicates the things in your case. also I had to add -- 'switch' to sudo to make it stopping to scan the command for switches and treat the rest as a whole command to execute –  Serge Sep 27 '12 at 3:13
    
One more question. Maybe related....If I run above command from a command line as php use it's ok. If I run from the browser it's ok but the first line is "Pseudo-terminal will not be allocated because stdin is not a terminal." Any idea? –  Radek Sep 27 '12 at 3:34
    
Do you need pty to be allocated? I suppose - no, taking to account that you run it from php script on a web server. Just remove -t switch –  Serge Sep 27 '12 at 3:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.