I'll take an RSX Type-S in Nighthawk Black Pearl with black leather, please. Oh, and tack on the 7-spoke aluminum wheels and the fog lights, thanks.
foreach $recipient_number (@{$process_recipient_bridge[$process]}) {process_recipient_bridge is an array of arrays (or list of lists, if you will). I want to get access to one of those internal lists. To get a single element in an array of arrays, you would use $array[index1][index2]. To get a whole array out, you still use $array[index1], but then you have to cast that as an array: @{$array[index1]}.
#! /usr/bin/perl
#
#---------------------------------------------------------#
# CAD Process Alert Script #
# ------------------------ #
# #
# Usage: #
# Run as a cron job. The script will verify that #
# specific processes are running on CAD. If any #
# of the processes are not running, emails and #
# pages will be sent to specified admins. There #
# will be no output to log files or the terminal. #
# #
# Configuration: #
# Process list: This is an array of arrays. The #
# syntax is ["process_name", "alert"] for each #
# item. Process name is what the script will #
# look for in the process list. The alert is #
# a description of the problem that will be sent #
# to the admins. #
# #
# Recipient list: This is an array of email #
# accounts that will be sent an email when there #
# is a problem with a process on CAD. Make #
# sure to place a slash ("\") before the "@" #
# sign in all email addresses. #
# Example: "email\@CENSORED" #
# #
# Process to recipient bridge: This is a list #
# of lists. Each list corresponds to a specific #
# process (thus, the first list corresponds to #
# the first process). Said list contains the #
# indices for the email recipients (thus if a #
# list contains [4,7,10], the recipients at the 4, #
# 7, and 10 indices of the recipient list will be #
# sent an email. #
# #
#---------------------------------------------------------#
@process_list = (
["ora_pmon_citrix", "The ora_pmon_citrix process is not running on CAD.\n\n
Please check the status of your Citrix servers"],
["ora_pmon_prod", "The ora_pmon_prod process is not running on CAD.\n\n
Please check the status of your Iman services"],
["LISTENE", "The Oracle listener process is not running on CAD.\n\n
Please check the status of your Citrix servers."],
);
@recipient_list = (
"CENSORED"
);
@process_recipient_bridge = (
[0,1,2,3,5,6,7,8],
[1,6],
[0,1,2,3,5,6,7,8],
);
sub process_check {
my $process = shift(@_);
$process_name = $process_list[$process][0];
$ps_text = `ps -ef | grep $process_name | grep -v grep`;
if ($ps_text =~ /$process_name/) {
return (0);
}
return (1);
}
sub send_alert {
my $process = shift(@_);
$alert = $process_list[$process][1];
foreach $recipient_number (@{$process_recipient_bridge[$process]}) {
$recipient = $recipient_list[$recipient_number];
open (MAIL, "|mailx -s \"CAD Process Check Failed\" $recipient");
print MAIL $alert;
close MAIL;
}
}
for ($lcv=0; $lcv<@process_list; $lcv++) {
if ( process_check($lcv) == 1) {
send_alert($lcv);
}
}