Subversion Repositories camp_sysinfo_client_3

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 rodolico 1
#! perl -w
2
# yes, I got tired of Perl deciding it was going to be one place or 
3
# another, so I just say "look in the path". Of course, if /tmp is
4
# in the path . . . .
5
 
6
# script takes a standard sendmail message formatted file (you know the
7
# one, where you have From:, To:, etc...), pulls the header info out, 
8
# then uses that to send via the sendEmail script.
9
# this way, you can use a standard format for an e-mail, but conver it
10
# to something else.
11
# of course, that means you are formatting one way, then reformatting
12
# another, but it is better than rewriting your main script.
13
 
14
my $mailServer;
15
my $smtpUser;
16
my $smtpPass;
17
my $config = '/root/sysinfo_mail';
18
 
19
my $emailScript = '/opt/sendEmail/sendEmail.pl';
20
my $logFile = '/tmp/mail.log';
21
my $tls = "'auto'";
22
 
23
# just pre-delaring some variables
24
my $from;
25
my $to;
26
my $subject;
27
my $cc;
28
my $bcc;
29
my $message;
30
 
31
if ( -e '/root/sysinfo_mail' ) {
32
   open DATA,"<$config" or die "Could not read config $config: $!\n";
33
   my $commands = join( '', <DATA> );
34
   die "Could not parse $config\n" unless eval( $commands );
35
}
36
 
37
while ( $line = <> ) {
38
   if ( $line =~ m/^From:\s+(.*)$/ ) {   
39
      $from = $1;   
40
      chomp $from;   
41
   }
42
   if ( $line =~ m/^To:\s+(.*)$/ ) { 
43
      $to = $1;
44
      chomp $to;
45
   }
46
   if ( $line =~ m/^Subject:\s+(.*)$/ ) {
47
      $subject = $1;
48
      chomp $subject;
49
   }
50
   if ( $line =~ m/^cc:\s+(.*)$/ ) {
51
      $cc = $1;
52
      chomp $cc;
53
   }
54
   if ( $line =~ m/^bcc:\s+(.*)$/ ) {
55
      $bcc = $1;
56
      chomp $bcc;
57
   }
58
   if ( $line =~ m/^$/ ) { # blank line, so the rest is the message
59
      $message = join( '', <> );
60
   }
61
}
62
 
63
#print "From: $from\nTo: $to\nSubject: $subject\n";
64
#print "cc: $cc\n" if $cc;
65
#print "bcc: $bcc\n" if $bcc;
66
#print "\n$message";
67
 
68
my %CLIParams ;
69
$CLIParams{'-f'}  = qq/$from/;
70
$CLIParams{'-t'}  = qq/$to/;  
71
$CLIParams{'-u'}  = qq/$subject/;
72
$CLIParams{'-s'}  = qq/$mailServer/;
73
$CLIParams{'-xu'} = qq/$smtpUser/;  
74
$CLIParams{'-xp'} = qq/$smtpPass/;  
75
$CLIParams{'-cc'} = qq/$cc/ if $cc; 
76
$CLIParams{'-bcc'}= qq/$bcc/ if $bcc;
77
$CLIParams{'-l'}  = qq/$logFile/;
78
$CLIParams{'-o tls='} = qq/$tls/ if $tls;
79
 
80
$commandLine = qq/$emailScript/;
81
 
82
die "Could not find executable $commandLine in sendEmailScript\n" unless -x $commandLine;
83
$commandLine .= ' -q'; # make it act quietly
84
foreach my $key ( keys %CLIParams ) {
85
   # depending on whether the key ends in an = or not, we will or will not use a space
86
   # between the key and the parameter
87
   $commandLine .= $key =~ m/=$/ ? " $key'$CLIParams{$key}'" : " $key '$CLIParams{$key}'";
88
}
89
$commandLine .= ' ' . $$parameters{'otherCLParams'} if $$parameters{'otherCLParams'};
90
#print "$commandLine\n";
91
open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
92
print SENDMAIL $message;
93
close SENDMAIL;