[sclug] sudo / su
Jacqui Caren
jacqui.caren at ntlworld.com
Wed Jan 10 08:28:59 UTC 2007
Spencer Collyer wrote:
> This should run the command in a subshell.
from man sudo on my gateway
% sudo sh -c "cd /home ; du -s * | sort -rn > USAGE"
The trick is to avoid anything that allows the current shell to glob
or to handle redirects (input and output *if* that is what you
want.
Note the sh (change to bash) used to ensure >, pipe and '*' is globbed.
Jacqui
p.s. I would have changed the ';' to && - this way the du is not
executed unless the cd works.
Also I would fully specify the path to du and sort
if this si a script.
More information about the Sclug
mailing list