0: #!/usr/bin/perl
1: # daniel j shahin
2: # metadb.pl - make a dbm of filenames and it's stats for later comparison
3: # only a little useful, could add checksum too...
4: # you may distribute this under the same terms as perl
5:
6: #use strict;
7: use DB_File;
8: use vars qw($COMMAND $DIRNAME $FILENAME $COLOR @filestats
9: @dbstats @statnames %HASH $i $file $stat );
10: if (@ARGV < 3){die "usage: metadb [makedb | compare] <directory> <dbm>"}
11: $COMMAND = shift;
12: $DIRNAME = shift;
13: $FILENAME = shift;
14:
15: @statnames = ('device', 'inode', 'mode', 'nlink',
16: 'uid', 'gid', 'rdev', 'size', 'atime',
17: 'mtime', 'ctime', 'blksize', 'blocks');
18:
19: if ($COMMAND eq 'makedb'){
20: dbmopen (%HASH, $FILENAME, 0666) or die "Can't open $FILENAME: $!\n";
21: opendir(DIR, $DIRNAME) or die "can't opendir $DIRNAME: $!";
22: while (defined($file = readdir(DIR))) {
23: next if $file =~ /^\.\.?$/;
24: $stat = join(':',stat("$DIRNAME/$file"));
25: $HASH{"$DIRNAME/$file"} = $stat;
26: print "$DIRNAME/$file: $stat \n";
27: }
28: closedir(DIR);
29: dbmclose %HASH;
30: }elsif($COMMAND eq 'compare'){
31: dbmopen %HASH, $FILENAME, 0666 or die "Can't open $FILENAME: $!\n";
32: opendir(DIR, $DIRNAME) or die "can't opendir $DIRNAME: $!";
33: while (defined($file = readdir(DIR))) {
34: next if $file =~ /^\.\.?$/;
35: $stat = join(':',stat("$DIRNAME/$file"));
36: if(exists $HASH{"$DIRNAME/$file"} && $HASH{"$DIRNAME/$file"} ne $stat){
37: if (exists $HASH{"$DIRNAME/$file"}){
38: print "$DIRNAME/$file\n";
39: @filestats = split(':', $stat);
40: @dbstats = split(':', $HASH{"$DIRNAME/$file"});
41: for ($i=0; $i<13; $i++){
42: print "\t$statnames[$i]";
43: print "\tfile:$filestats[$i]";
44: print "\tdb:$dbstats[$i]\n";
45: }
46: }
47: }
48: }
49: }
In reply to metadb.pl
by dshahin
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.