Skip to content

Instantly share code, notes, and snippets.

@antonlindstrom
Created May 5, 2009 15:11
Show Gist options
  • Save antonlindstrom/107000 to your computer and use it in GitHub Desktop.
Save antonlindstrom/107000 to your computer and use it in GitHub Desktop.
school assignment #6
#!/usr/bin/perl
#
# Mailing systeminfo to $admin
use Mail::Sendmail;
# Set mailadresses.
$admin = 'root@localhost';
$from = '[email protected]';
# Commands which output will be sent.
@commands = ("who", "uptime", "ps ax | grep apache2");
# Server hostname, nix hostname command.
$hostname = `hostname`;
chomp($hostname);
# Output in string $output.
foreach (@commands) {
$output .= "COMMAND: $_\n";
$output .= `$_`;
$output .= "\n";
}
# Print out in STDOUT.
print $output;
# Format mail.
%mail = ( To => $admin,
From => $from,
Subject => "Monitoring [$hostname] system.",
Message => $output
);
# Send mail.
sendmail(%mail) or die $Mail::Sendmail::error;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment