Linux perl--sending mail and monitoring memory

Source: Internet
Author: User
Tags server memory

#!perluse warnings;use strict;use net::smtp_auth;#&sendmail;while (1) {My ($sumMem, $freeMem, $rateMem); open MEM, " Cat/proc/meminfo | "or Die $!; while (<MEM>) {$sumMem = $ if (/memtotal:\s+ (\d+) \s+kb/), $freeMem + = if (/memfree:\s+ (\d+) \s+kb/); $freeMem + = $ if (/buffers:\s+ (\d+) \s+kb/); $freeMem + = (/cached:\s+ (\d+) \s+kb/);} $rateMem = sprintf ("%d", $freeMem/$sumMem *), if ($rateMem <=) {My $content = &detail;&sendmail ($content) ; Sleep (3600);} Sleep (60);} Sub detail{' Top-bn 1 > log '; open log, "head-100 log |" or Die $!; My $content, while (<LOG>) {next/^$/), my @top = Split/\s+/;if ($top [5] =~/g|t/and $top [0] =~/\d+/) {$content. = " $top [1]\t$top[5]\t$top[11]\n ";}} return $content;} Sub Sendmail{my $content = shift @_;my $smtpHost = ' smtp.exmail.qq.com '; my $smtpPort = ' + '; my $username = ' * * * @genedenov O.com '; my $passowrd = ' * * * '; My @to = (' * * * ', ' * * * '); my $suffix = "\ @genedenovo. com"; my $subject = "Please note that 19 server memory usage has exceeded 90%! "; My $message =" Details: $contentMonitoring program from $username "; my $smtp = Net::smtp_auth->new ($smtpHost, Timeout = +) or die" Error: Connection to $smtphost failed! "; $smtp->auth (' LOGIN ', $username, $passowrd) or Die (" Error: Authentication failed! My @address = map {My $i = $_. $suffix; $i} @to, my $x = join ",", @address; $smtp->mail ($username); $smtp->to (@address); $smtp->data (); $smtp Datasend ("to: $x \ n"); # Strict Format$smtp->datasend ("from: $username \ n"); # strict Format$smtp->datasend ("Subject: $subject \ n"); # strict Format$smtp->datasend ("content-type:text/plain;charset=utf-8\n"); # strict Format$smtp->datasend ("content-trensfer-encoding:7bit\n\n"); # strict Format$smtp->datasend ($message); $smtp->dataend (); $smtp->quit ();}

Linux perl--sending mail and monitoring memory

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.