Re: How to set file attributes



On Feb 26, 10:27 pm, John <John.Sm...@xxxxxxxxxxx> wrote:
Jim Gibson <jimsgib...@xxxxxxxxx> wrote:
In article <38t8s3550b7tipdjlg66u2ddmv8683k...@xxxxxxx>, John
<John.Sm...@xxxxxxxxxxx> wrote:

I have set up my own counter.pl on my web page.

The counter saves the visitation count to a text file called "count.txt".
How do I create the file (and later open) with file attributes that prevent
others reading the file, ie. going towww.johnsmith.com/count.txt (the www
here
is not real).

It depends upon the operating system. Under Unix, you would create the
file with an editor, the cat command, or the touch command (see 'man
cat', etc.). File permissions are set with the chmod command. You want
to set the file so that it is readable and writable only by the owner:

chmod 0600 count.txt

The problem is that for this to work, the file needs to be owned by the
web server process, and that may not be your own user id. Some web
servers use the user 'nobody', for example. As a result, you sometimes
have to set data files to be world writable:

chmod 0666 count.txt

So it also depends upon your user id, the web server's id, and whether
or not you have root privilege.

If you do have root privilege, then you can set the owner of the file
as well as the file permissions (as above):

chown nobody:nobody count.txt
chmod 0600 count.txt

But this is for Unix, not necessarily other operating systems.

Thanks for input. The web counter files should be seen my me only (I download the
files every day).

Setting the files chmod 0600 count.txt seems to do what I want.
The perl script creates a num conter file for every day. How do I create the new
file so that it has 0600 attributes?
$txtfi=open (MYCOUNT,"<"."count.txt");

use File::CounterFile;
http://search.cpan.org/~gaas/File-CounterFile-1.04/CounterFile.pm

The module uses sysopen without specifying the perm (which defaults to
0666) so you'd probably what to adjust the code in the module.

change:
sysopen(F, $file, O_RDWR|O_CREAT) or croak("Can't open $file: $!");

to:
sysopen(F, $file, O_RDWR|O_CREAT, 0600) or croak("Can't open $file:
$!");
.



Relevant Pages

  • Re: How to set file attributes
    ... file with an editor, the cat command, or the touch command (see 'man ... File permissions are set with the chmod command. ... web server process, and that may not be your own user id. ...
    (comp.lang.perl.misc)
  • Re: How to set file attributes
    ... file with an editor, the cat command, or the touch command (see 'man ... File permissions are set with the chmod command. ... web server process, and that may not be your own user id. ... If you do have root privilege, then you can set the owner of the file ...
    (comp.lang.perl.misc)
  • Re: How to set file attributes
    ... file with an editor, the cat command, or the touch command (see 'man ... File permissions are set with the chmod command. ... web server process, and that may not be your own user id. ... If you do have root privilege, then you can set the owner of the file ...
    (comp.lang.perl.misc)
  • Re: Permission Denied when writing to a file
    ... command line or otherwise manipulate the file permissions, ... 'man chmod' will get you the information that you need. ...
    (comp.lang.php)
  • coreutils-5.94 released [stable]
    ... [basename cat chgrp chmod chown chroot cksum comm cp csplit cut date dd ... If that command fails because you don't have the required public key, ...
    (gnu.announce)