I am sharing a perl script here, which is supposed to send a mail with the HDD/RAM status in the message body: Also, the HDD out will happen only if the %HDD use is above 50%.
How can I include the declared variables (here,
@hdd
and@ram
) in the message body?How can I make the program terminate without sending the mail if the HDD usage is below 50%..? Or simply, the mail program should work if and only if the HDD % is above 50%.
In the below script, the HDD/RAM checking part is working fine, as well as the mail sending part is also working fine. Except, instead of the HDD/RAM values, "@hdd" and "@ram" are displayed directly in the received mail.
\#!/usr/bin/perl
@hdd = grep {$_ >50} (\`df -H`=~/(\S+%)/g);
@ram = \`free | grep Mem | awk '{print \$3/\$2 * 100.0}'`;
use MIME::Lite;
$to = '[email protected]';
$from = '[email protected]';
$subject = 'HDD / RAM alerts';
$message = 'The % HDD usage is @hdd and the % RAM usage is @ram';
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc => $cc,
Subject => $subject,
Data => $message
);
$msg->send;
Pardon me if the question is a little bit broad. But being beginner, please be kind enough to help it.