#!/usr/local/bin/perl ###################################################################### +# # Program: arcfile.pl # Description: Create an achive of a file with a new extension. # Author: Peter Marek # Date: October 23, 2000 ###################################################################### +# if($ARGV[0] eq '' || $ARGV[0] eq '-h'){ print "\nUsage: arcfile.pl [-c] filespec\n\n"; print "\t[-c]\t\tCompress the archive\n"; print "\tfilespec\tAny UNIX regular typeglob expression\n\n"; exit 0; } # CREATE A HASH FOR MONTH NAME TO NUMERICAL EQUIVALENT %xref=('Jan' => '01', 'Feb' => '02', 'Mar' => '03', 'Apr' => '04', 'May' => '05', 'Jun' => '06', 'Jul' => '07', 'Aug' => '08', 'Sep' => '09', 'Oct' => '10', 'Nov' => '11', 'Dec' => '12'); # RIP APART THE SYSTEM DATE COMPONENTS $_=localtime; my ($month,$date,$year,$time)=(split)[1,2,4,3]; # IF WE HAVE A 1 DIGIT DATE ZERO PAD TO THE LEFT if (length($date) eq 1) {$date='0' . $date;} # RIP APART THE SYSTEM TIME COMPONENTS $_=$time; my ($hours,$min,$sec)=(split/:/); # BUILD THE NEW FILE EXTENSION my $ext="$year$xref{$month}$date$hours$min"; # SPIN THROUGH THE EXPANDED LIST OF FILES foreach (@ARGV) { if($_ eq '-c'){next;} $arcfile=$_ . '.' . $ext; # OPEN THE ORIGINAL FILE die "Can't open file for reading!\n" unless open(INFILE,"<$_"); # OPEN THE NEW FILE die "Can't open file for writing!\n" unless open(OUTFILE,">$arcfil +e"); while (<INFILE>){ print OUTFILE; } # CLOSE THE ORIGINAL close INFILE; # CLOSE THE NEW FILE close OUTFILE; if($ARGV[0] eq '-c'){ @cmd=qw{gzip -9}; push @cmd,$arcfile; system(@cmd); warn "Could not change the permissions for $_.$ext.gz to read- +only" unless chmod 0444,"$arcfile.gz"; next; } # SET THE FILE PERMISSIONS OF THE ARC FILE TO READ-ONLY warn "Could not change the permissions for $_.$ext to read-only" unless chmod 0444, $arcfile; } #__________ POD __________ =head1 NAME arcfile.pl - Archive files using date/time file extension =head1 SYNOPSIS arcfile.pl [-c] filespec =item c This optional switch allows for compression of the archive. =item filespec The filespec can be either a single file name or a UNIX typeglob regul +ar expression that r esolves to a set of files. =head1 DESCRIPTION arcfile.pl will create a copy of the files represented by filespec wit +h an extension of YY YYMMDDhhmm (filespec.YYMMDDhhmm) All files created use the same file +extension regardless of how long the individual archive takes to process. THe permissions + of the archived fil es are then set to read-only (0444). =item YYYY = Current Year =item MM = Current Month =item DD = Current Day of Month =item hh = Current Hour =item mm = Current Minute =head1 AUTHOR Peter Marek, October 23 2000 =end
In reply to archive UNIX files by draconis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |