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 used to execute the command:

sudo -u elasticsearch -s "ulimit -Hn"

and it was returning the value of ulimit -Hn as seen by user elasticsearch until I tried it on Ubuntu 11.10. There it returns:

/bin/bash: ulimit -Hn: command not found

I tried a few different commands, and when I use an argument I always get "command not found":

$ sudo -u elasticsearch -s "ls all.sh"
/bin/bash: ls all.sh: command not found

Any ideas on how can I execute a command that requires arguments through sudo?

Thanks!

share|improve this question
    
why the -s? Just keep the normal shell and use it to execute commands. Such as sudo -u elasticsearch ls all.sh. If elasticsearch has an unusable default shell, use -s bash before the actual command. –  glglgl Nov 12 '11 at 10:21
add comment

1 Answer 1

up vote 10 down vote accepted

You need to remove the double-quotes. It is trying to run a command called "ulimit -Hn" as a single command, spaces and all. -s needs to be the last sudo option on the sudo command line, and all following arguments are passed to $SHELL -c to execute.

sudo -u elasticsearch -s ulimit -Hn

I guess the way -s is processed has changed, as the current way allows you to pass arguments with spaces to $SHELL by escaping them on the command line:

$ touch '/tmp/foo bar'
$ sudo -s rm '/tmp/foo bar'

The old method of argument handling would split that '/tmp/foo bar' argument into two, breaking the command.

share|improve this answer
add comment

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.