File: run-subtree.old

package info (click to toggle)
cricket 1.0.5-9
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,480 kB
  • ctags: 390
  • sloc: perl: 8,287; sh: 920; ansic: 318; makefile: 62; sql: 16
file content (66 lines) | stat: -rwxr-xr-x 1,823 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/local/bin/perl -w
# -*- perl -*-

# Cricket: a configuration, polling and data display wrapper for RRD files
#
#    Copyright (C) 1998 Jeff R. Allen and WebTV Networks, 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 2 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, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#
# run a cricket subtree and send any output to the provided email addresses
#

use strict;
use Getopt::Long;
use Net::SMTP;
use Net::DNS;

my $result	= "";
my @output	= ();

my $doMail = 'smrtg@corp.webtv.net';
my $doSubtree;

$result = GetOptions(	"mail|m=s" => \$doMail, 
			"subtree|s=s" => \$doSubtree,
		    );

if (!$result) {
	die "Error handling options.\n";
}
if (!defined($doSubtree)) {
	die "Must provide a subtree to run.\n";
}

@output = `$ENV{"HOME"}/cricket/collect-subtrees $doSubtree 2>&1`;

if ($#output > 0) {
	my $res = Net::DNS::Resolver->new;
	my ($eUser, $eDomain) = split(/\@/, $doMail);

	my @mx = mx($res, $eDomain);

	my $subject = "output from subtree " . $doSubtree;

	my $smtp = Net::SMTP->new($mx[0]->{'exchange'}, Debug => 1);
	$smtp->mail($doMail);
	$smtp->to($doMail);
	$smtp->data();
	$smtp->datasend("Subject: $subject");
	$smtp->datasend(@output);
	$smtp->dataend();
	$smtp->quit;
}