University Crest

[wlug] sudo and writing to /var/log

 
wlug archive index About the wlug list Mailing lists home
To The University of Waikato HomepageWaikato Home > Waikato Mailing Lists > wlug Info > wlug archives
A. Pagaltzis pagaltzis@g...
Wed Nov 30 17:21:50 NZDT 2005


* Daniel Lawson <daniel@m...> [2005-11-30 03:35]:
> All is not lost - run the command AND the redirection from
> 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
annoyance:

    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.)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>




More information about the wlug mailing list
NOTICE: This is an archive of a public mailing list. The University of Waikato is not responsible for its contents.

The University of Waikato - Te Whare Wananga o Waikato