File Permissions using NIS and NFS and copying via perl

A

alerman

I have written a script that copies files from a test server to a
production server. The userID's and groupID's are the same on both
servers and we are using NIS.

I set the permissions on the test server to alerman:www-data (I own it,
it is in the web users group) so that the web server can read and
execute it.

The files copy over to the new server, but are always alerman:alerman .
This means that my web server cant read them because of permissions
issues.

Any suggestions?

I have tried both File::Copy and using `cp -p from to`
 
C

cgrady357

If the file owner is changing when you FTP the files to the new server,
then you should put them in an archive first before transferring them.
Then when you expand the archive on the new server, the permissions
will remain the same.

If the issue is that files' owner is different to begin with, then this
code should help:
use File::Copy;

sub chg_owner {
my $dir = shift;
my $sep = shift;
my @files = @_;
for my $file(@files) {
$file = "$dir$sep$file";
if(! -s $file) { die ("Missing file: $file");}
if( -l $file) {$file = readlink $file; }
my $uid = (stat($file))[4] or die("File stat failed $file");
my $owner = getpwuid($uid) or die("Getpwuid failed on $uid");
next if ($owner eq "www-data");
my $newfile = $file . ".bk";
copy($file,$newfile) or die("Copy failed: $file to $newfile $!");
unlink $file or die("Unlink failed: $file $!");
move($newfile,$file) or die("Copy failed: $newfile to $file $!");
print "Changed owner of $file from $owner to www-data\n");
}
}
 
B

Big and Blue

I have written a script that copies files from a test server to a
production server. The userID's and groupID's are the same on both
servers and we are using NIS.

I set the permissions on the test server to alerman:www-data (I own it,
it is in the web users group) so that the web server can read and
execute it.

The files copy over to the new server, but are always alerman:alerman .
This means that my web server cant read them because of permissions
issues.

Any suggestions?

I have tried both File::Copy and using `cp -p from to`

If cp -p isn't setting the group then either it is broken or the process
doing it is *not* in the www-data group.

After a copy which has set the group to alerman try:

chgrp www-data <1-file>

and see what happens.

However, it's not clear where the Web server comes into this. I'm
assuming it isn't involved in doing any of the actual copying.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top