[Chicago-talk] Permission?
Andrew Rodland
arodland at comcast.net
Sat Dec 16 12:57:37 PST 2006
On Saturday 16 December 2006 12:58 pm, Richard Reina wrote:
> Andrew,
>
> Thank you very much for the reply. I was hoping not to have to change the
> permissions on the directory, but I guess I will have to. Thanks for the
> insight.
>
> Richard
Well, it's not _impossible_ to do it without write permission on the dir, it
just takes a bit more work than the way you had. One possibility is (in
perl):
open my $fh, '<', 'my_log.txt';
<$fh>;
my @lines = <$fh>;
open $fh, '>', 'my_log.txt';
print $fh @lines;
But since this doesn't use a rename() it does involve a small possibility that
if the program crashes at just the wrong moment, the file contents will be
lost entirely. You could work around that with something more like (in sh):
set -e
TEMP = `mktemp`
(read junk; cat) < my_log.txt > $TEMP
cat $TEMP > my_log.txt
rm $TEMP
which has a few complications of its own, but which, if it happens to crash,
should always leave a good copy of the data in the logfile, or in /tmp. It's
not stunningly robust, but what do you expect for a couple minutes'
effort? ;)
HTH
Andrew
More information about the Chicago-talk
mailing list