#!/usr/bin/perl -lw my $scriptissue = "Issue 1.0 26/09/04 John Cooper"; use File::Find (); use Cwd; # if no argument given, default to current directory my $startdir = cwd(); @ARGV = $startdir unless @ARGV; # if argument given , overwrite cwd $startdir = "@ARGV"; # convert /usr/bin to _usr_bin for filename ($startdir = $startdir) =~ s/\//_/g; # get the current date to append to output filename my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(tim +e); my $cyear = $year+1900; my $cmonth = $mon+1; if ( $cmonth < 10 ) {$cmonth = "0" . $cmonth;} my $cday = $mday; if ( $cday < 10 ) { $cday = "0" . $cday; } my $cdate = "_$cday" . "_$cmonth" . "_$cyear"; $txtfileout = "permrestore" . $startdir . $cdate; # subroutines sub time_as_date($) { my ($time) = @_; my $date = localtime($time); return $date; } sub print_info($) { my ($name) = @_; use File::stat; my $info = stat($name)my $size = $info->size; # size in bytes my $atime = $info->atime; # time of last access (seconds since epoch) my $mtime = $info->mtime; # time of last data modification my $ctime = $info->ctime; # time of last file status change # discard file type info from 'mode' and put in usual numeric format my $perms = sprintf("%04o", $mode & 07777); # convert times (in seconds since the epoch) to date strings my $adate = time_as_date($atime); my $mdate = time_as_date($mtime); my $cdate = time_as_date($ctime); + # print out the desired fields in tab-separated format print "\# ORIG PERM = $filename\t$uid\t$gid\t$perms\t$mdate"; print "chmod $perms $filename"; print "chown $uid:$gid $filename"; # write out to text file print TOUT "\# ORIG PERM = $filename\t$uid\t$gid\t$perms\t$mdate"; print TOUT "chmod $perms $filename"; print TOUT "chown $uid:$gid $filename"; } sub find(&@) { &File::Find::find } # Main programme print "\nPerl script to log filename permissions and owners"; print "which can be executed to re-establish them if they are changed" +; print "\nLog output to file $txtfileout"; print "Start directory is @ARGV"; print "\nUsage: logperm.pl [directory]"; print "\n Do you want to continue (y/n)? "; $answer = <STDIN>; if ( $answer =~ m/^[y,Y](.*)/ ) { open TOUT,">$txtfileout" or die "Cannot open output file $txtfileout : + $!\n"; *name = *File::Find::name; find { \&print_info($name) } @ARGV; close TOUT; my $mode = 0755; chmod $mode, $txtfileout; print "\nMake log file executable - chmod 755 $txtfileout"; print "Finished - $scriptissue"; } else { print "User answered no, log not created, quitting...." }

In reply to Owner Permissions restore script by johnc10

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.