diff --git a/Makefile b/Makefile index 6158c99..18e36c3 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,10 @@ -all: blink/blink.1 histogram/histogram.1 upsidedown/upsidedown.1 tracefile/tracefile.1 timestamp/timestamp.1 rand/rand.1 rrm/rrm.1 goodpasswd/goodpasswd.1 +CMD = blink histogram upsidedown tracefile timestamp rand rrm goodpasswd -blink/blink.1: blink/blink - pod2man blink/blink > blink/blink.1 +all: blink/blink.1 goodpasswd/goodpasswd.1 histogram/histogram.1 rand/rand.1 rrm/rrm.1 timestamp/timestamp.1 tracefile/tracefile.1 upsidedown/upsidedown.1 wssh/wssh.1 -goodpasswd/goodpasswd.1: goodpasswd/goodpasswd - pod2man goodpasswd/goodpasswd > goodpasswd/goodpasswd.1 +%.1: % + pod2man $< > $@ -histogram/histogram.1: histogram/histogram - pod2man histogram/histogram > histogram/histogram.1 - -rand/rand.1: rand/rand - pod2man rand/rand > rand/rand.1 - -rrm/rrm.1: rrm/rrm - pod2man rrm/rrm > rrm/rrm.1 - -timestamp/timestamp.1: timestamp/timestamp - pod2man timestamp/timestamp > timestamp/timestamp.1 - -tracefile/tracefile.1: tracefile/tracefile.pod - pod2man tracefile/tracefile.pod > tracefile/tracefile.1 - -upsidedown/upsidedown.1: upsidedown/upsidedown - pod2man upsidedown/upsidedown > upsidedown/upsidedown.1 - -wssh/wssh.1: wssh/wssh - #pod2man wssh/wssh > wssh/wssh.1 install: mkdir -p /usr/local/bin diff --git a/rrm/rclean b/rrm/rclean new file mode 100755 index 0000000..c058618 --- /dev/null +++ b/rrm/rclean @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +use Digest::MD5::File qw(dir_md5_hex file_md5_hex url_md5_hex); + +my $dir = shift || "."; + +chdir $dir; + + +# Table of which files have a given size +open(IN,"-|",'find "`pwd`" -type f -printf "%s\t%p\0"') || die; +$/="\0"; +my %size; +while() { + chop; # Remove \0 + my($s,$f) = split /\t/,$_; + push @{$size{$s}}, $f; +} +close IN; + +# Read md5sum of removed files of a given size +my %rrm; +my $rrmfile = find_rrm_file(".") || ".rrm"; +open(RRM,"<",$rrmfile) || die; +while() { + my($size,$md5,$file) = split /\t/,$_; + $rrm{0+$size}{$md5}++; +} +close RRM; + +# Which existing files are the same size as some of the removed files? +for my $size (keys %rrm) { + for my $file (@{$size{$size}}) { + if(-e $file) { + my $md5 = Digest::MD5->new; + $md5->addpath($file); + # Do they have the same md5sum? + if($rrm{$size}{$md5->hexdigest}) { + # remove this + print "$file\n"; + } + } + } +} + +sub find_rrm_file { + my $dir = shift; + if(-r "$dir/.rrm") { + return "$dir/.rrm"; + } + if(join(" ",stat $dir) eq join(" ",stat "$dir/..")) { + # root + return undef; + } else { + return find_rrm_file("$dir/.."); + } +} diff --git a/rrm/rrm b/rrm/rrm new file mode 100755 index 0000000..056de39 --- /dev/null +++ b/rrm/rrm @@ -0,0 +1,84 @@ +#!/usr/bin/perl + +=encoding utf8 + +=head1 NAME + +rrm - record and remove file + + +=head1 SYNOPSIS + +B I + + +=head1 DESCRIPTION + +B records a file's MD5sum before removing it. It makes it +possible to automatically remove the file again should it ever +reappear. + +This is useful for cleaning up photos where other partial backups of +the photos are later added: Photos removed once can easily be +identified and removed automatically if added by the backup. + + +=head1 EXAMPLE + +B IMG_2035.JPG + +Restore a backup containing I. + +B + +B will find B as it has the same size and MD5sum +as an already removed file. + + +=head1 FILES + +The file B<.rrm> contains the database of size, md5sum, and names of +the files. It is created in current directory if it cannot be found in +any of the (grand*)parent directories. + + +=head1 SEE ALSO + +B(1), B(1), B(1) + + +=cut + + +use Digest::MD5::File qw(dir_md5_hex file_md5_hex url_md5_hex); + +my %size; +my %md5; +for my $file (@ARGV) { + if(-s $file > 0) { + $size{$file} = -s $file; + my $md5 = Digest::MD5->new; + $md5->addpath($file); + $md5{$file} = $md5->hexdigest; + } +} + +$rrmfile = find_rrm_file(".") || ".rrm"; + +open(RRM,">>",$rrmfile) || die("Cannot write to $rrmfile."); +print RRM map { $size{$_}."\t".$md5{$_}."\t".$_."\0\n" } @ARGV; +close RRM; +unlink @ARGV; + +sub find_rrm_file { + my $dir = shift; + if(-r "$dir/.rrm") { + return "$dir/.rrm"; + } + if(join(" ",stat $dir) eq join(" ",stat "../$dir")) { + # We have reached root dir (.. = .) + return undef; + } else { + return find_rrm_file("../$dir"); + } +} diff --git a/timestamp/timestamp.1 b/timestamp/timestamp.1 index c94e662..a2e1ac1 100644 --- a/timestamp/timestamp.1 +++ b/timestamp/timestamp.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) +.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== @@ -38,6 +38,8 @@ . ds PI \(*p . ds L" `` . ds R" '' +. ds C` +. ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. @@ -48,17 +50,24 @@ .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. -.ie \nF \{\ -. de IX -. tm Index:\\$1\t\\n%\t"\\$2" +.\" +.\" Avoid warning from groff about undefined register 'F'. +.de IX .. -. nr % 0 -. rr F -.\} -.el \{\ -. de IX +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" .. +. if !\nF==2 \{ +. nr % 0 +. nr F 2 +. \} +. \} .\} +.rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -124,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TIMESTAMP 1" -.TH TIMESTAMP 1 "2014-02-14" "perl v5.14.2" "User Contributed Perl Documentation" +.TH TIMESTAMP 1 "2016-05-23" "perl v5.18.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -145,10 +154,10 @@ and now. If \fB\-\-delta\fR is repeated: The time spent between each line. .IP "\fB\-\-rfc\fR" 9 .IX Item "--rfc" -Output time format in \s-1RFC822\s0 (E.g. Wed, 30 Jan 2013 13:57:58 \s-1GMT\s0). +Output time format in \s-1RFC822 \s0(E.g. Wed, 30 Jan 2013 13:57:58 \s-1GMT\s0). .IP "\fB\-\-iso\fR" 9 .IX Item "--iso" -Output time format in \s-1ISO8601\s0 (E.g. 2013\-01\-30T13:57:58.322). +Output time format in \s-1ISO8601 \s0(E.g. 2013\-01\-30T13:57:58.322). .IP "\fB\-\-iso\-time\fR" 9 .IX Item "--iso-time" Output time format in ISO8601/time only (E.g. 13:57:58.322). @@ -179,8 +188,8 @@ the Free Software Foundation; either version 3 of the License, or at your option any later version. .PP This program is distributed in the hope that it will be useful, -but \s-1WITHOUT\s0 \s-1ANY\s0 \s-1WARRANTY\s0; without even the implied warranty of -\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS\s0 \s-1FOR\s0 A \s-1PARTICULAR\s0 \s-1PURPOSE\s0. See the +but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of +\&\s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE. \s0 See the \&\s-1GNU\s0 General Public License for more details. .PP You should have received a copy of the \s-1GNU\s0 General Public License diff --git a/tracefile/tracefile b/tracefile/tracefile index 7c238d1..fdb026f 100755 --- a/tracefile/tracefile +++ b/tracefile/tracefile @@ -1,5 +1,200 @@ #!/usr/bin/perl +=head1 NAME + +tracefile - list files being accessed + +=head1 SYNOPSIS + +B [-aenu] I + +B [-aenu] -p I + +=head1 DESCRIPTION + +B will print the files being accessed by the command. + +=head1 OPTIONS + +=over 9 + +=item I + +Command to run. + + +=item B<-a> + +List all files. + + +=item B<-e> + +List only existing files. + + +=item B<-n> + +List only non-existing files. + +=item B<-p> I + +Trace process id. + + +=item B<-u> + +List only files once. + +=back + + +=head1 EXAMPLES + +=head2 EXAMPLE: Find the missing package + +Assume you have a program B. When it runs it fails with: I. It does not say with file is missing, but you +have a hunch that you just need to install a package - you just do not +know which one. + + tracefile -n -u foo | apt-file -f search - + +Here B tries to find B. If it fails, +B will search for which package it is in: + + tracefile -n -u ls /usr/include/shisa.h | apt-file -f search - + +=head1 REPORTING BUGS + +Report bugs to . + + +=head1 AUTHOR + +Copyright (C) 2012 Ole Tange, http://ole.tange.dk and Free +Software Foundation, Inc. + + +=head1 LICENSE + +Copyright (C) 2012 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +at your option any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +=head2 Documentation license I + +Permission is granted to copy, distribute and/or modify this documentation +under the terms of the GNU Free Documentation License, Version 1.3 or +any later version published by the Free Software Foundation; with no +Invariant Sections, with no Front-Cover Texts, and with no Back-Cover +Texts. A copy of the license is included in the file fdl.txt. + +=head2 Documentation license II + +You are free: + +=over 9 + +=item B + +to copy, distribute and transmit the work + +=item B + +to adapt the work + +=back + +Under the following conditions: + +=over 9 + +=item B + +You must attribute the work in the manner specified by the author or +licensor (but not in any way that suggests that they endorse you or +your use of the work). + +=item B + +If you alter, transform, or build upon this work, you may distribute +the resulting work only under the same, similar or a compatible +license. + +=back + +With the understanding that: + +=over 9 + +=item B + +Any of the above conditions can be waived if you get permission from +the copyright holder. + +=item B + +Where the work or any of its elements is in the public domain under +applicable law, that status is in no way affected by the license. + +=item B + +In no way are any of the following rights affected by the license: + +=over 2 + +=item * + +Your fair dealing or fair use rights, or other applicable +copyright exceptions and limitations; + +=item * + +The author's moral rights; + +=item * + +Rights other persons may have either in the work itself or in +how the work is used, such as publicity or privacy rights. + +=back + +=back + +=over 9 + +=item B + +For any reuse or distribution, you must make clear to others the +license terms of this work. + +=back + +A copy of the full license is included in the file as cc-by-sa.txt. + +=head1 DEPENDENCIES + +B uses Perl, and B. + + +=head1 SEE ALSO + +B(1) + +=cut + use Getopt::Long; $Global::progname = "tracefile"; diff --git a/tracefile/tracefile.pod b/tracefile/tracefile.pod deleted file mode 100644 index 04cac03..0000000 --- a/tracefile/tracefile.pod +++ /dev/null @@ -1,197 +0,0 @@ -#!/usr/bin/perl - -=head1 NAME - -tracefile - list files being accessed - -=head1 SYNOPSIS - -B [-aenu] I - -B [-aenu] -p I - -=head1 DESCRIPTION - -B will print the files being accessed by the command. - -=head1 OPTIONS - -=over 9 - -=item I - -Command to run. - - -=item B<-a> - -List all files. - - -=item B<-e> - -List only existing files. - - -=item B<-n> - -List only non-existing files. - -=item B<-p> I - -Trace process id. - - -=item B<-u> - -List only files once. - -=back - - -=head1 EXAMPLES - -=head2 EXAMPLE: Find the missing package - -Assume you have a program B. When it runs it fails with: I. It does not say with file is missing, but you -have a hunch that you just need to install a package - you just do not -know which one. - - tracefile -n -u foo | apt-file -f search - - -Here B tries to find B. If it fails, -B will search for which package it is in: - - tracefile -n -u ls /usr/include/shisa.h | apt-file -f search - - -=head1 REPORTING BUGS - -Report bugs to . - - -=head1 AUTHOR - -Copyright (C) 2012 Ole Tange, http://ole.tange.dk and Free -Software Foundation, Inc. - - -=head1 LICENSE - -Copyright (C) 2012 Free Software Foundation, Inc. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3 of the License, or -at your option any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . - -=head2 Documentation license I - -Permission is granted to copy, distribute and/or modify this documentation -under the terms of the GNU Free Documentation License, Version 1.3 or -any later version published by the Free Software Foundation; with no -Invariant Sections, with no Front-Cover Texts, and with no Back-Cover -Texts. A copy of the license is included in the file fdl.txt. - -=head2 Documentation license II - -You are free: - -=over 9 - -=item B - -to copy, distribute and transmit the work - -=item B - -to adapt the work - -=back - -Under the following conditions: - -=over 9 - -=item B - -You must attribute the work in the manner specified by the author or -licensor (but not in any way that suggests that they endorse you or -your use of the work). - -=item B - -If you alter, transform, or build upon this work, you may distribute -the resulting work only under the same, similar or a compatible -license. - -=back - -With the understanding that: - -=over 9 - -=item B - -Any of the above conditions can be waived if you get permission from -the copyright holder. - -=item B - -Where the work or any of its elements is in the public domain under -applicable law, that status is in no way affected by the license. - -=item B - -In no way are any of the following rights affected by the license: - -=over 2 - -=item * - -Your fair dealing or fair use rights, or other applicable -copyright exceptions and limitations; - -=item * - -The author's moral rights; - -=item * - -Rights other persons may have either in the work itself or in -how the work is used, such as publicity or privacy rights. - -=back - -=back - -=over 9 - -=item B - -For any reuse or distribution, you must make clear to others the -license terms of this work. - -=back - -A copy of the full license is included in the file as cc-by-sa.txt. - -=head1 DEPENDENCIES - -B uses Perl, and B. - - -=head1 SEE ALSO - -B(1) - -=cut - diff --git a/wssh/wssh b/wssh/wssh index 45952d5..eb64816 100755 --- a/wssh/wssh +++ b/wssh/wssh @@ -1,5 +1,69 @@ #!/usr/bin/perl +=head1 NAME + +wssh - wait for ssh port to open and then ssh + + +=head1 SYNOPSIS + +B [sshoptions] I + + +=head1 DESCRIPTION + +B waits for port 22 to open and then Bs to the given I. + + +=head1 EXAMPLE + +B + + +=head1 EXIT STATUS + +Returns the same as B. + + +=head1 REPORTING BUGS + +Contact Ole Tange . + + +=head1 AUTHOR + +Copyright (C) 2012 Ole Tange . + + +=head1 LICENSE + +Copyright (C) 2012 Free Software Foundation, Inc. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +at your option any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + + +=head1 DEPENDENCIES + +B uses Perl, and B. + + +=head1 SEE ALSO + +B(1) + +=cut + use Getopt::Long; my @argv = @ARGV;