Created
May 5, 2009 15:11
-
-
Save antonlindstrom/107000 to your computer and use it in GitHub Desktop.
school assignment #6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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