[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: touch: enhancement request to preserve file ownership and permission
RE: touch: enhancement request to preserve file ownership and permissions
Thu, 13 Sep 2007 17:16:40 +0930
Knew there had to be a better way :-)
savelog doesn't come standard in on the RHEL system that I'm using so will look
I've found logrotate good for regular cron jobs but tedious to run manually
From: Bob Proulx [mailto:address@hidden
Sent: Thu 9/13/2007 4:12 PM
To: Peter Newman
Subject: Re: touch: enhancement request to preserve file ownership and
Peter Newman wrote:
> should be in this order (can't chmod before you touch):
> 'touch --ref=reffile yourfile && chmod --ref=reffile yourfile'
The order does not matter if the file already exists. But as you saw
in my other note I agreed with this order when the file did not
previously exist and this creates it.
> but what I really want is to have this:
> 'touch --ref=reffile yourfile && chmod --ref=reffile yourfile && chown
> --ref=reffile yourfile '
Ah... But chown is an entirely different thing and opens up an
entirely different box of problems. And it leads me to ask what
operating system you are working on? SysV Unix allows non-root users
to chown files. BSD Unix and all modern kernels since then only allow
the superuser to chown files.
> OR as suggested:
> 'touch -pr=reffile yourfile' (cause I'm lazy)
I am cautious. Is this really something that needs to be done often
enough to justify adding the problems of chmod and chown into touch?
I think this would be pretty rare and these operations can be done
using other commands.
> The purpose of this is to clear a log file like this: "> file" but
> you have to be a user with permission to do this
But if the process does not have permission then the proposed enhanced
touch won't be able to do this either.
> and if you're not then "sudo > file" doesn't work
The redirection happens before the sudo. You have to put the
redirection into the sudo'd command itself.
sudo sh -c '> file'
> where "sudo mv log log.old; sudo touch -pr=log.log log" will.
Have you looked at using 'savelog' or 'logrotate'? In my opinion this
is a task better done by those. Using 'savelog' is a perfect fit here.
sudo savelog -p log
Do you really want to truncate? Or do you really want to rotate?
Those are two different problems.