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 John on March 9, 2008, 12:26 pm
Please log in for more thread options

$sec=open(TEKST,">test.txt");
chmod 0600,$sec;
binmode(TEKST);
print TEKST ""hello world";
close TEKST;


Why is the test.txt not chmodded to 0600 but to 0755

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

> 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;


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

Posted by Gunnar Hjalmarsson on March 9, 2008, 1:51 pm
Please log in for more thread options
Joost Diepenmaat 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 $!;

With sysopen() you can do it in one step:

sysopen TEKST, 'test.txt', O_WRONLY|O_CREAT, 0600 or die $!;

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

Posted by John on March 9, 2008, 4:44 pm
Please log in for more thread options

>
>> 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


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

>>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

That's strange. With that code you should only get permissions of 0600
or less (when umask is set to something other than 0).

What are the owners and permissions of text.txt and its containing
directory prior to running the command?

What operating system & perl version are you using?

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

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