3 # parse command line options
15 sshsendmail - Uses ssh to send a mail message to a different machine's copy of sendmail.
22 --host, -H host to upload image to
23 --dir, -D dir to place image (on host of -H set)
24 --import-options, -I options to import (default -window root)
25 --convert-options, -C options to convert (for scaling)
26 --scale, -s make scaled image (default)
27 --debug, -d debugging level (Default 0)
28 --help, -h display this help
29 --man, -m display manual
35 =item B<--identity, -i>
37 ssh identity to send to the server we're connecting to
41 Debug verbosity. (Default 0)
45 Display brief useage information.
57 Will pretty much do what you want
61 Will take a picture of a window you select.
66 use File::Basename qw(basename);
74 # XXX parse config file
76 my %options = (debug => 0,
82 log => '/var/mail/log',
83 'sendmail-options' => '',
86 GetOptions(\%options,'identity|i=s','username|l=s','daemon|d', 'syslog|s',
87 'sendmail-options|o=s','log|l=s',
90 pod2usage() if $options{help};
91 pod2usage({verbose=>2}) if $options{man};
93 $DEBUG = $options{debug};
96 print STDERR "${0}: Too few command-line arguments\n";
98 usage: ${0} [flags] remote-address < mail-file
99 Send an email message via ssh+sendmail
100 -p, --port=INT Set the port number on the remote host to connect to
101 -d, --daemon use syslog exclusively (Debian only)
102 -s, --syslog use syslog additionally (Debian only)
104 -h, --help Display this help and exit
109 my $hostname = shift @ARGV;
112 #throw away envelope sender
116 while (my $line = shift @message) {
117 last if $line eq "\n";
119 push @recipients,$line;
122 @recipients = qw(-t) if not @recipients;
124 my @ssh_arguments = ($hostname);
126 push @ssh_arguments, '-i', $options{identity} if defined $options{identity};
127 push @ssh_arguments, '-l', $options{username} if defined $options{username};
128 push @ssh_arguments, q(cat - | /usr/lib/sendmail ).$options{'sendmail-options'}.' '.join(' ',@recipients);
129 qx(ping -q -c 3 $hostname 2>/dev/null);
131 print STDERR "${0}: Failed: unable to ping $hostname\n";
134 my $ssh = new IO::Handle;
135 my $log = new IO::File $options{log},'w+' or exit(2);
136 print {$log} @message or exit(2);
137 print {$log} join(' ',('ssh',@ssh_arguments)) or exit(2);
138 open($ssh,'|-','ssh',@ssh_arguments) or exit(17);
139 print {$ssh} @message or exit(17);
140 close $ssh or exit(17);
142 print STDERR "${0}: Failed: sendmail died for some reason\n";
143 print {$log} "${0}: Failed: sendmail died for some reason\n";
147 print STDERR "${0}: Succeeded: Yeay\n";
148 print {$log} "${0}: Failed: sendmail died for some reason\n";