]> git.donarmstrong.com Git - bin.git/blobdiff - sshsendmail
add scan stuff
[bin.git] / sshsendmail
index 69fd3edfc06946eb26a6fa2d1a19a4030e0b852d..866847024fd2bff170f589033e241ce189cfd0bc 100755 (executable)
@@ -1,4 +1,9 @@
 #! /usr/bin/perl
+# sshsendmail uses ssh to send a mail message to a different machine,
+# and is released under the terms of the GPL version 2, or any later
+# version, at your option. See the file README and COPYING for more
+# information.
+# Copyright 2005-10 by Don Armstrong <don@donarmstrong.com>.
 
 # parse command line options
 
@@ -16,14 +21,18 @@ sshsendmail - Uses ssh to send a mail message to a different machine's copy of s
 
 =head1 SYNOPSIS
 
-ss [options]
+Stick this command in /usr/lib/nullmailer/sshsendmail.
+
+Then add
+
+foohost.com sshsendmail --identity=/var/mail/.ssh/id_rsa --username remotemail --sendmail-options='-baruser@foohost.com'
+
+to /etc/nullmailer/remotes.
 
  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)
+  --identity, -i ssh identity to use to connect to the server
+  --username, -l remote username
+  --sendmail-options, -o options to pass to sendmail
   --debug, -d debugging level (Default 0)
   --help, -h display this help
   --man, -m display manual
@@ -50,15 +59,6 @@ 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
 
@@ -79,12 +79,11 @@ my %options = (debug              => 0,
               host               => undef,
               identity           => undef,
               username           => undef,
-              log                => '/var/mail/log',
-              'sendmail-options' => '',
+              'sendmail_options' => [''],
              );
 
 GetOptions(\%options,'identity|i=s','username|l=s','daemon|d', 'syslog|s',
-          'sendmail-options|o=s','log|l=s',
+          'sendmail_options|sendmail-options|o=s@',
           'help|h|?','man|m');
 
 pod2usage() if $options{help};
@@ -125,26 +124,23 @@ 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);
+push @ssh_arguments, q(cat - | /usr/lib/sendmail ).
+    join(' ',ref($options{sendmail_options})?@{$options{sendmail_options}}:($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}: Succeeded: Yeay\n";
      exit 0;
 }