develooper Front page | perl.beginners | Postings from February 2002

Re: How to copy and keep file permissions

Thread Previous | Thread Next
From:
zentara
Date:
February 21, 2002 08:10
Subject:
Re: How to copy and keep file permissions
Message ID:
rj4a7ug92gs6nibf8ssvutamjqprpf9mco@4ax.com
On Wed, 20 Feb 2002 17:17:20 +0000, cemberly@UU.NET (Craig Eberly) wrote:

>Hmm, I've tried this but it doesn't seem to change the file permissions at
>all on the backup file.  I checked into it, and my stat command or  $mode in
>this case is equal to 33261.   Is that a normal output for the mode in the
>stat command?  I'm on a Solaris 8 system.

The 33261 is file permissions and file type in decimal.
Under linux, chmod accepts this value, maybe under solaris
you have to to have the octal value?  

Try this instead:

#!/usr/bin/perl
use warnings;
use File::Copy;
use strict;
my $mode = (stat $ARGV[0])[2]; #decimal unmasked 
my $mode = sprintf("%04o", $mode & 07777) ; #octal masked off
print $mode,"\n";
copy( "$ARGV[0]", "$ARGV[0]\.bak" );
chmod ($mode, "$ARGV[0]\.bak");
print "Backup completed.\n";
exit 0;



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About