#!/usr/local/bin/perl # # This proggy searches for files with resembling names. (I hope...) # # You don't need to understand this code ;) # ...or then you have to, after all. Tough luck. # # $FTP = "/ftp-service/ftp/"; $INCOMING_MAIN = "incoming/"; $INCOMING_MSDOS = "incoming/msdos/"; $MSDOS_PROG_MAIN = "pub/msdos/programming/"; $TARGET = "000-findlog"; $PRLN = length($FTP); $LS = "/bin/ls"; print "\nScanning directories...\n\n"; # Note: Be VERY carefull with the LS options, as symbolic links # May confuse the system easily, resulting in infinite loop. # # ---------------------------------------- $path = $INCOMING_MAIN; open (M, "$LS -1LF $FTP$path | grep -v '/' |") || die "cannot stat '$FTP$path'"; print " $path:\t\t\t"; do scan_dir(); close (M); # ---------------------------------------- $path = $INCOMING_MSDOS; open (M, "$LS -1RF $FTP$path |") || die "cannot stat '$FTP$path'"; print " $path:\t\t"; do scan_dir(); close (M); # ---------------------------------------- $path = $MSDOS_PROG_MAIN; open (M, "$LS -1RF $FTP$path |") || die "cannot stat '$FTP$path'"; print " $path:\t"; do scan_dir(); close (M); # ---------------------------------------- # oolrait nytten on muistissa tiedostojen polut ja tyypit # ja eikun listan tekoon. # Open output files printf "\nWriting to $TARGET\n"; open (T, ">$TARGET"); foreach $key (sort {$a cmp $b} keys %List) { ($List{$key} && grep (/incoming/, $List{$key})) && print T "$List{$key}\n"; } print T "\n"; close (T); chmod 0664, $TARGET; # ---------------------------------------- ## ## Muodosta hash-pattern, jolla kukin tiedosto indeksoidaan listassa. ## $F_TXT = 1; $F_ZIP = 2; $F_ARJ = 4; $F_INV = 8; # invalid $F_NON = 16; # unknown type sub scan_dir { $n =0; l1: while () { chop; if (/^\s*$/) { next l1; } if (/(\S*):/) { $path = substr($1, $PRLN); next l1; } # get current directory if (/\S+\/$/) { next l1; } # subdirectory if (grep (/\~/, $_)) { print "*** backup file $path/$_\n"; } $tmp = $_; $tmp =~ tr/A-Z\-/a-z_/; # lowercase ($base, $ext, @rest) = split (/\./, $tmp, 3); $base =~ tr/0-9//d; # ignore numbers $List{$base} .= $path . "/" . $_ . " "; # add # if (grep (/txt|doc/, $ext)) { $flgs{$base} |= $F_TXT; } # elsif (grep (/zip|lha/, $ext)) { $flgs{$base} |= $F_ZIP; } # elsif (grep (/ar/, $ext)) { $flgs{$base} |= $F_ARJ; } # elsif (grep (/exe/, $ext)) { $flgs{$base} |= $F_INV; } # else { $flgs{$base} |= $F_NON; } $n++; } print "$n files\n"; }