#!/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

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.