-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.pl
executable file
·129 lines (93 loc) · 3.32 KB
/
main.pl
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl
use strict;
use warnings;
use Env;
use Term::ANSIColor;
use List::MoreUtils qw(uniq);
use Text::ASCIITable;
use MIME::Lite;
our $cmd_current_date = "date +\"%d-%m-%Y\"";
our $current_date = `$cmd_current_date` ;
#-- initialise tables
our $t = Text::ASCIITable->new({ headingText => "Oracle Patches Status as of $current_date" });
$t->setCols("instance_name","hostname", "psu_patch_id", "psu_release_date", "ojvm_patch_id", "ojvm_release_date", "one_off_patch_id", "one_off_patch_id2");
our $config_file = "/oracle/scripts/patch_parser/db_lookup.php";
our $patch_parser = "/oracle/scripts/patch_parser/patch_parser.pl";
our $cmd_cat = "cat $config_file | grep -i conn_str";
our @hosts = `$cmd_cat`;
our @host_list;
our $elem;
our $uniq_host;
our $stripped;
our $str;
#-- Define table columns
our $instance_name;
our $hostname;
our $psu_patch_id;
our $psu_release_date;
our $ojvm_patch_id;
our $ojvm_release_date;
our $one_off_patch_id;
our $one_off_patch_id2;
#-- Delete old logfile
our $cmd_del_log = "rm -f /oracle/scripts/patch_parser/*.log 2>/dev/null";
`$cmd_del_log`;
foreach $elem (@hosts)
{
(my $stripped) = ($elem =~ /conn_str\>(.*)\:/);
push @host_list, $stripped;
}
#-- get unique hostnames
our @distinct_hosts = uniq @host_list;
print "@distinct_hosts \n";
foreach $uniq_host (@distinct_hosts)
{
print "Running Patch checker for $uniq_host \n";
our $ssh_command = "ssh oracle\@$uniq_host perl < $patch_parser >> /oracle/scripts/patch_parser/patch.log";
print "$ssh_command \n";
system ($ssh_command);
}
#-- Delete column names
our $cmd_dele_col = "sed -i '/instance_name/d' /oracle/scripts/patch_parser/patch.log";
`$cmd_dele_col`;
#-- trim the spaced between each value in a row
our $cmd_trim_space = "tr -s \" \" < /oracle/scripts/patch_parser/patch.log > /oracle/scripts/patch_parser/opatch.log";
`$cmd_trim_space`;
#-- Format the values generated into tabularised form
open (FILE, "/oracle/scripts/patch_parser/opatch.log") || die "Cannot open your file";
while (my $line = <FILE> )
{
chomp $line;
our @sid = $line =~ /^(.*?):\//;
($instance_name , $hostname, $psu_patch_id, $psu_release_date, $ojvm_patch_id, $ojvm_release_date, $one_off_patch_id, $one_off_patch_id2 ) = split / /, $line;
$t->addRow($instance_name , $hostname, $psu_patch_id, $psu_release_date, $ojvm_patch_id, $ojvm_release_date, $one_off_patch_id, $one_off_patch_id2);
}
print $t;
open(my $fh, '>', '/oracle/scripts/patch_parser/report.txt');
print $fh "$t";
close $fh;
#--------------------------------------------------------------------------------------------
#Email report to DBA's and Yao #
#-------------------------------------------------------------------------------------------
my $msg;
my $mail_host='';
my $report_filename_with_path = "/oracle/scripts/patch_parser/report.txt";
my $report_file_name= "report.txt";
$msg = MIME::Lite->new(
From => '',
To => '',
Cc => '',
Subject => 'Databases Patch Level',
Type => 'multipart/mixed'
);
$msg->attach (
Type => 'TEXT',
Data => 'See attachments'
);
$msg->attach (
Type =>'text/html; charset="iso-8859-1"',
Path => $report_filename_with_path,
Filename => $report_file_name,
Disposition => 'attachment'
);
$msg->send('smtp', $mail_host);