Click here to get back home

Setting chmod

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Setting chmod John 03-09-2008
---> Re: Setting chmod Joost Diepenmaa...03-09-2008
Posted by Gunnar Hjalmarsson on March 9, 2008, 5:17 pm
Please log in for more thread options
John wrote:
>>> Why is the test.txt not chmodded to 0600 but to 0755
>>
>> Because $sec is not a file name or a file handle. It's a good idea to
>> check if any file operation succeeded:
>>
>> open(TEKST,">test.txt") or die $!;
>> chmod 0600,*TEKST or die $!;
>> binmode(TEKST);
>> print TEKST "hello world";
>> close TEKST;
>
> I still got different result. This time I've got 0644

Did you check the return value from chmod() as suggested? When I run the
code as above, I got a "No such file or directory" error message. Then I
tried

chmod 0600, 'test.txt' or die $!;

which worked.

Please also see my other message in this thread.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Joost Diepenmaat on March 9, 2008, 5:26 pm
Please log in for more thread options

>>> open(TEKST,">test.txt") or die $!;
>>> chmod 0600,*TEKST or die $!;
>>> binmode(TEKST);
>>> print TEKST "hello world";
>>> close TEKST;

[ ... ]

> Did you check the return value from chmod() as suggested? When I run
> the code as above, I got a "No such file or directory" error
> message.

AFAIK the code as posted above should work in systems that support
fchmod() - basically any recent Unix - and should generate a fatal error
at line 2 on systems that don't.

Whatever it does it should never give a "No such file or directory
error". At least not at line 2.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Posted by Gunnar Hjalmarsson on March 9, 2008, 6:42 pm
Please log in for more thread options
Joost Diepenmaat wrote:
>
>>>> open(TEKST,">test.txt") or die $!;
>>>> chmod 0600,*TEKST or die $!;
>>>> binmode(TEKST);
>>>> print TEKST "hello world";
>>>> close TEKST;
>
> [ ... ]
>
>> Did you check the return value from chmod() as suggested? When I run
>> the code as above, I got a "No such file or directory" error
>> message.
>
> AFAIK the code as posted above should work in systems that support
> fchmod() - basically any recent Unix - and should generate a fatal error
> at line 2 on systems that don't.
>
> Whatever it does it should never give a "No such file or directory
> error". At least not at line 2.

$ cat test.pl
print "$^O\n";
open(TEKST,">test.txt") or die $!;
chmod 0600,*TEKST or die $!;
$ perl test.pl
linux
No such file or directory at test.pl line 3.
$ ls -l test.txt
-rw-rw-r-- 1 gunnarh gunnarh 0 Mar 9 18:42 test.txt
$

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by Joost Diepenmaat on March 9, 2008, 6:54 pm
Please log in for more thread options

> $ cat test.pl
> print "$^O\n";
> open(TEKST,">test.txt") or die $!;
> chmod 0600,*TEKST or die $!;
> $ perl test.pl
> linux
> No such file or directory at test.pl line 3.
> $ ls -l test.txt
> -rw-rw-r-- 1 gunnarh gunnarh 0 Mar 9 18:42 test.txt
> $

Agh. I just checked and this code only runs as I described in perl 5.8.8
and higher. Older perls don't accept file handles as arguments to chmod.


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Posted by Gunnar Hjalmarsson on March 9, 2008, 9:48 pm
Please log in for more thread options
Joost Diepenmaat wrote:
>
>> $ cat test.pl
>> print "$^O\n";
>> open(TEKST,">test.txt") or die $!;
>> chmod 0600,*TEKST or die $!;
>> $ perl test.pl
>> linux
>> No such file or directory at test.pl line 3.
>> $ ls -l test.txt
>> -rw-rw-r-- 1 gunnarh gunnarh 0 Mar 9 18:42 test.txt
>> $
>
> Agh. I just checked and this code only runs as I described in perl 5.8.8
> and higher. Older perls don't accept file handles as arguments to chmod.

That explains it; I'm using v5.8.1.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Similar ThreadsPosted
chmod for directories August 9, 2004, 2:22 pm
Problems with chmod February 28, 2006, 6:23 pm
Recursive chmod/chown February 3, 2006, 10:46 am
ExtUtils chmod on Windows? August 10, 2007, 8:57 am
setting uid gid after fork August 28, 2007, 3:35 am
setting %ENV in a module February 20, 2008, 7:59 pm
Re: Setting up mod_perl March 10, 2008, 2:50 pm
Re: Setting up mod_perl March 11, 2008, 11:17 pm
Net::DNS-> About setting more than one nameserver to lookup. August 7, 2004, 9:05 pm
setting cookies (mod_perl) October 14, 2004, 9:15 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap