Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NNM email Perl script - Unix timestamp not wanted 1

Status
Not open for further replies.

martyNZ

Technical User
Oct 29, 2003
7
0
0
NZ
As the previous thread, I too want to use Mr Bowden's perl script. However, I don't care much for the Unix "Epoch" timestamp that it imposes. So...can anyone help with the re-writing of the script to take the time arg out? The simple solution is to put the generic HP OV var for the time ($X) in the message part....but I'm sure we can all do a better job than that...


Thanks team.
Here's the crux part of the script:

###################################################

my ($node, $alert, $time, @email_addresses) = @ARGV;

# check that we have the miminum fields which we require
if (! ($node && $alert && $time) ) {
die "You must supply a value for the node, alert message and time !\nNode = $node\nMessage = $alert\nTime = $time\n\n";
}

$time = localtime($time); # convert to readable format

my $msg = ("$time : $node : $alert\n");

# connect to the smtp server
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host : $MAILHOST - $!\n";

# add email addresses configured in @EMAIL_TO to any email addresses
# passed in args from command line
@email_addresses = (@email_addresses, @EMAIL_TO);

foreach my $address (@email_addresses) {

$smtp->mail($address);
$smtp->to($address);
$smtp->data();
$smtp->datasend("From: $FROM\n");
$smtp->datasend("To: $address\n");
$smtp->datasend("Subject: $alert : $node\n");
$smtp->datasend("\n$msg \n\n");
$smtp->datasend;
$smtp->dataend();
}
$smtp->quit;

################################################################
 
aaah - solved it with some editing.
###########################################
my ($node, $alert, @email_addresses) = @ARGV;

# check that we have the miminum fields which we require
if (! ($node && $alert) ) {
die "You must supply a value for the node, alert message !\nNode = $node\nMessage =

$alert\n\n";
}


my $msg = ("$node : $alert\n");

# connect to the smtp server
my $smtp = Net::SMTP->new($MAILHOST, Timeout => 10) or die "Unable to connect to mail host :

$MAILHOST - $!\n";

# add email addresses configured in @EMAIL_TO to any email addresses
# passed in args from command line
@email_addresses = (@email_addresses, @EMAIL_TO);

foreach my $address (@email_addresses) {

$smtp->mail($address);
$smtp->to($address);
$smtp->data();
$smtp->datasend("From: $FROM\n");
$smtp->datasend("To: $address\n");
$smtp->datasend("Subject: $alert : $node\n");
$smtp->datasend("\n$msg \n\n");
$smtp->datasend;
$smtp->dataend();
}
$smtp->quit;
#####################################################
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top