--- /dev/null
+#! /usr/bin/perl
+
+# parse command line options
+
+# connect to host
+
+use warnings;
+use strict;
+
+use Getopt::Long;
+use Pod::Usage;
+
+=head1 NAME
+
+sshsendmail - Uses ssh to send a mail message to a different machine's copy of sendmail.
+
+=head1 SYNOPSIS
+
+ss [options]
+
+ Options:
+ --host, -H host to upload image to
+ --dir, -D dir to place image (on host of -H set)
+ --import-options, -I options to import (default -window root)
+ --convert-options, -C options to convert (for scaling)
+ --scale, -s make scaled image (default)
+ --debug, -d debugging level (Default 0)
+ --help, -h display this help
+ --man, -m display manual
+
+=head1 OPTIONS
+
+=over
+
+=item B<--identity, -i>
+
+ssh identity to send to the server we're connecting to
+
+=item B<--debug, -d>
+
+Debug verbosity. (Default 0)
+
+=item B<--help, -h>
+
+Display brief useage information.
+
+=item B<--man, -m>
+
+Display this manual.
+
+=back
+
+=head1 EXAMPLES
+
+ ss
+
+Will pretty much do what you want
+
+ ss -I
+
+Will take a picture of a window you select.
+
+=cut
+
+use User;
+use File::Basename qw(basename);
+use IO::Handle;
+use IO::File;
+
+use vars qw($DEBUG);
+
+$0 = basename($0);
+
+# XXX parse config file
+
+my %options = (debug => 0,
+ help => 0,
+ man => 0,
+ host => undef,
+ identity => undef,
+ username => undef,
+ log => '/var/mail/log',
+ 'sendmail-options' => '',
+ );
+
+GetOptions(\%options,'identity|i=s','username|l=s','daemon|d', 'syslog|s',
+ 'sendmail-options|o=s','log|l=s',
+ 'help|h|?','man|m');
+
+pod2usage() if $options{help};
+pod2usage({verbose=>2}) if $options{man};
+
+$DEBUG = $options{debug};
+
+if (not @ARGV) {
+ print STDERR "${0}: Too few command-line arguments\n";
+ print <<END;
+usage: ${0} [flags] remote-address < mail-file
+Send an email message via ssh+sendmail
+ -p, --port=INT Set the port number on the remote host to connect to
+ -d, --daemon use syslog exclusively (Debian only)
+ -s, --syslog use syslog additionally (Debian only)
+
+ -h, --help Display this help and exit
+END
+ exit(1);
+}
+
+my $hostname = shift @ARGV;
+
+my @message = <>;
+#throw away envelope sender
+shift @message;
+my @recipients;
+
+while (my $line = shift @message) {
+ last if $line eq "\n";
+ chomp $line;
+ push @recipients,$line;
+}
+
+@recipients = qw(-t) if not @recipients;
+
+my @ssh_arguments = ($hostname);
+
+push @ssh_arguments, '-i', $options{identity} if defined $options{identity};
+push @ssh_arguments, '-l', $options{username} if defined $options{username};
+push @ssh_arguments, q(cat - | /usr/lib/sendmail ).$options{'sendmail-options'}.' '.join(' ',@recipients);
+qx(ping -q -c 3 $hostname 2>/dev/null);
+if ($?) {
+ print STDERR "${0}: Failed: unable to ping $hostname\n";
+ exit (9);
+}
+my $ssh = new IO::Handle;
+my $log = new IO::File $options{log},'w+' or exit(2);
+print {$log} @message or exit(2);
+print {$log} join(' ',('ssh',@ssh_arguments)) or exit(2);
+open($ssh,'|-','ssh',@ssh_arguments) or exit(17);
+print {$ssh} @message or exit(17);
+close $ssh or exit(17);
+if ($?) {
+ print STDERR "${0}: Failed: sendmail died for some reason\n";
+ print {$log} "${0}: Failed: sendmail died for some reason\n";
+ exit (17);
+}
+else {
+ print STDERR "${0}: Succeeded: Yeay\n";
+ print {$log} "${0}: Failed: sendmail died for some reason\n";
+ exit 0;
+}