use Net::Ping;
use Net::FTP;
use Net::SMTP;
$hostfile = "/mnt/homes/CLASSES/CIS2279/LAB13/hosts.txt";
$p = Net::Ping->new();
open(HF, "<$hostfile") || die "cannot open file: $!";
while($host = <HF>) {
chomp($host);
$rc = $p->ping($host);
if($rc) {
print "host $host is up.\n";
}else{
print "host $host is off-line\n";
}
}
close(HF);
$host = 'mirror.csclub.uwaterloo.ca';
$ftp_user = 'anonymous';
$ftp_pass = 'mark.tucker@lyndonstate.edu';
$remote_path = '/slackware/slackware64-14.2';
print "Retrieveing file via FTP...\n";
$ftp = Net::FTP->new($host, -Passive=>'true');
$ftp->login($ftp_user,$ftp_pass) or die "Cannot login: ", $ftp->message;
$ftp->cwd($remote_path) or die "Cannot change directory: ", $ftp->message;
chdir($ENV{'HOME'}); $ftp->get("RELEASE_NOTES") or die "Cannot get file: ", $ftp->message;
$ftp->quit;
$file = $ENV{'HOME'}.'/RELEASE_NOTES';
open(RN, "<$file") || die "cannot read file: $!";
$counter = 0;
while($line = <RN>) {
push(@eight, $line);
$counter++;
last if($counter >= 7);
}
close(RN);
print "Now sending an email...\n";
$from = 'student@metlab99.lsc.vsc.edu';
$mailhost = 'lsc-smtp.lsc.vsc.edu';
$address = 'mark.tuckerm@lsc.vsc.edu';
$subject = 'Eight lines of the Release Notes';
$smtp = Net::SMTP->new($mailhost, Timeout=>30);
$smtp->mail($from);
$smtp->to($address);
$smtp->data();
$smtp->datasend("Subject: $subject\n\n"); foreach $k (@eight) {
$smtp->datasend("$k\n");
}
$smtp->dataend();
$smtp->quit;
exit;