Tuesday, June 17, 2008

Weird sudo situation

Recently, I hit a weird situation where i had use sudo.
I wanted to do the following with privileges

$ sudo echo 1 > /proc/sys/kernel/panic_on_oops

The above is what anyone will try, which didn't work because it sudoes "echo 1"
not the redirection ">"

The solution is
$ sudo sh -c "echo 1 > /proc/sys/kernel/panic_on_oops"

So we create a new sudo shell and -c tells the shell to execute the command mentioned in
the string.

1 comment:

Anki said...

One can do this as well:

$ echo 1 |sudo tee -a /proc/sys/kernel/panic_on_oops