#!/usr/bin/perl
$recipiant='me\@foo.com'
$hostname='foodles'

push  ( @a, "##############################################################\n");

open(WHO, "/usr/bin/w |") || die "can't run w:\t$!\n";
@a=(<WHO>);
close(WHO)  || die "can't close w file handle:\t$!\n";

push  ( @a, "##############################################################\n");

open(NETSTAT, "netstat -a -n|") || die "can't run netstat:\t$!\n";
push ( @a,(<NETSTAT>)); 
close(NETSTAT)  || die "can't close netstat file handle:\t$!\n";

push  ( @a, "##############################################################\n");

open(LSOF_TCP, "lsof -i tcp -nP|") || die "can't run lsof -i tcp:\t$!\n";
push ( @a, (<LSOF_TCP>));
close(LSOF_TCP)  || die "can't close lsof tcp file handle:\t$!\n";

push  ( @a, "##############################################################\n");

open(LSOF_UDP, "lsof -i udp -nP|") || die "can't run lsof -i tcp:\t$!\n";
push ( @a, (<LSOF_UDP>));
close(LSOF_UDP)  || die "can't close lsof tcp file handle:\t$!\n";

push  ( @a, "##############################################################\n");

open (MAIL, "| mailx -s '[root login] $hostname' $recipiant" ) || die   "can't run mail program:\t$!\n";

print MAIL @a,"\n";
