* Daniel Lawson <daniel(a)meta.net.nz> [2005-11-30 03:35]:
All is not lost - run the command AND the redirection
within the sudo command:
sudo /bin/bash -c " date > /var/log/logfile"
That runs an extra shell and the command itself as root though,
when all you need root privs for is to open the file.
You can avoid such needless privileges using a minimal process to
write to the file that takes the destination file as a parameter
and opens it itself, instead of using shell redirection. Then you
can run *only* that process as root. Un-/fortunately, the common
Unix toolbox has a suitable tool, but one that involves a minor
date | sudo tee /var/log/logfile > /dev/null
The annoyance being, of course, that this forces you to pipe
STDOUT to the bit bucket.
(If you need to append rather than overwrite, tee(1) has an `-a`
switch, so that’s also covered.)
Aristotle Pagaltzis // <http://plasmasturm.org/>