Gossamer Forum
Home : General : Perl Programming :

Creating automatically with desired permissions.

Quote Reply
Creating automatically with desired permissions.
open (LOGFILE, ">/home/database.db") ;
print LOGFILE "Here goes the data\n";
close (LOGFILE) ;


Above given is the simple script. IF database.db is not existing script will create the file automatically. But the problem is it is created with the permissions of 0644. I want to create it with permission 0666 by the script. I tried.

open (LOGFILE, ">/home/database.db") ;
print LOGFILE "Here goes the data\n";
close (LOGFILE) ;
chmod (0666, '/home/database.db');


But it's not working, any solution to it?

Thanks,

Zeshan.



Last edited by:

zeshan: Mar 28, 2003, 4:38 PM
Quote Reply
Re: [zeshan] Creating automatically with desired permissions. In reply to
You should always use error checking. Currently you aren't using any =)

Code:
open (LOGFILE, ">/home/database.db") or die "Can't open: $!";

Code:
chmod (0666, '/home/database.db') or die "Can't chmod: $!";
Quote Reply
Re: [Paul] Creating automatically with desired permissions. In reply to
Should I Open First or Chmod first?

Thanks for your help.

I really needed that.
Quote Reply
Re: [zeshan] Creating automatically with desired permissions. In reply to
Well you can't chmod a non existant file so you need to open first.