How to zero out a logfiles
donald.ritchey at exeloncorp.com
donald.ritchey at exeloncorp.com
Thu Apr 1 09:36:57 EST 2004
Another way to do this, that preserves the concepts of the original
request is:
sudo sh -c "echo > /var/log/admfile"
The reason that the original method fails is that the redirection is
done in the original user's shell, and he/she does not have permission
to open the log file as the non-root user ID.
The command listed above works because the redirection of standard out
occurs in the context of a root-owned shell. This is important because
many times you will want to run a command as another user and need to
send the output to a file that you personally don't have permission to
open. The general method to handle that is"
sudo sh -c "command_to_run 1 or more parameters >log_file 2>error_file"
Hope this clarifies the situation.
Best wishes.
Donald L. (Don) Ritchey
E-mail: Donald.Ritchey at exeloncorp.com
-----Original Message-----
From: Stephen Carville [mailto:stephen at totalflood.com]
Sent: Wednesday, March 31, 2004 7:53 PM
To: Sudo Users
Subject: Re: How to zero out a logfiles
On Wednesday March 31 2004 01:16 pm, Jim Horwath wrote:
> Hi all,
>
> I have been using sudo for a few months and I'm still
> learning the ropes. I need to zero a logfile with sudo, but
> I can't get the '>' syntax just right. I tried to search
> the archives but didn't find any hints. I can't be the
> first (or last) person who wants to do this.
>
> For example:
>
> sudo echo > /var/adm/logfile
>
> or something similiar
The only way I know how is:
echo | sudo tee /var/log/admfile
--
Stephen Carville
UNIX and Network Administrator
DPSI
310-342-3602
stephen at totalflood.com
--
If you have been voting for politicians who promise to give you goodies at
someone else's expense, then you have no right to complain when they take
your money and give it to someone else, including themselves.
--Thomas Sowell (1992)
____________________________________________________________
sudo-users mailing list <sudo-users at sudo.ws>
For list information, options, or to unsubscribe, visit:
http://www.sudo.ws/mailman/listinfo/sudo-users
************************************************************************
This e-mail and any of its attachments may contain Exelon Corporation
proprietary information, which is privileged, confidential, or subject
to copyright belonging to the Exelon Corporation family of Companies.
This e-mail is intended solely for the use of the individual or entity
to which it is addressed. If you are not the intended recipient of this
e-mail, you are hereby notified that any dissemination, distribution,
copying, or action taken in relation to the contents of and attachments
to this e-mail is strictly prohibited and may be unlawful. If you have
received this e-mail in error, please notify the sender immediately and
permanently delete the original and any copy of this e-mail and any
printout. Thank You.
************************************************************************
More information about the sudo-users
mailing list