Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A small Perl utility 1

Status
Not open for further replies.

rycamor

Programmer
Jun 3, 1999
1,426
US
Since I was frustrated at having to constantly type:
tar -zpscf tarfilename directoryname, I whipped up this little Perl utility which compresses an entire directory, preserves permissions, and names the archive after the directory, while appending the current date and time into the name:

Code:
#!/usr/bin/perl
$dir_in=shift(@ARGV);
chomp($dir_in);
print "Archiving $dir_in/* ...\n";
use POSIX qw(strftime);
$now_string = strftime "%m-%d-%Y_%H%M", localtime;
$tarname=$dir_in."_".$now_string.".tar.gz";
$execstring="tar -zpscf ".$tarname." ".$dir_in."/*";
#print($execstring); # for debugging...
system($execstring);
print("\n");

I called this "rarch" for "recursive archiver", and placed it in /usr/local/bin. Now, let's say I have a directory called "htmlfiles", and I want to archive and compress the whole directory, and be able to tell at a glance exactly when I did this, I just go one level outside that directory and type "rarch htmlfiles" (without the trailing slash "/"). This creates a gzipped tarfile called htmlfiles_07-23-2001_1027.tar.gz (Assuming current time is 7/23/2001 at 10:27 AM)

Obviously, since this does not also use Seconds in the time, you will overwrite the last file if you call it twice in the same minute. I don't archive things often enough to worry about seconds ;-).

Anyone have any comments or additions? I would like to get a library of similar Perl system utilities together. Any good links for that sort of thing?
 
Would anyone have a tip on how to get the above utility to estimate the amount of time it will take for an operation and report back on the progress while the user is waiting?
(useful when tarring and gzipping a large dir)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top