Marketing 101. Consulting 101. PHP Consulting. Random geeky stuff. I Blog Therefore I Am.


PHP Free Space Monitor Code

<?php
# script to get the amount of free space with df -h and email it
# to me daily

include "../z/class.phpmailer.php";

  $freespace = mysystem("df -h");
  $fortune = mysystem ("/usr/games/fortune");

  $email = "scott@fuzzygroup.com";
  //setup the email object & params
  $mail = new phpmailer();
  $mail->IsMail();
  $mail->From = "webmaster@fuzzygroup.com";
  $mail->FromName = "Free Space Mailer";
  $mail->AddAddress("$email");
  $mail->AddReplyTo("scott@fuzzygroup.com");
  $mail->IsHTML(false);
  $mail->Subject = "Free Space On FuzzyGroup Server";
  $mail->Body    = $freespace . "\n\n\n\n" . $fortune;

  if(!$mail->Send())
  {
    echo "Error -- Can't Email User Info<p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
  }
  else {
    print "<pre>$freespace <BR><BR>$fortune</PRE>";
    exit;
  }

function mysystem($command) {
 if (!($p=popen("($command)2>&1","r"))) {
  return 126;
 }

 while (!feof($p)) {
  $line=fgets($p,1000);
   $out .= $line;
 }
 pclose($p);
 return $out;
}


?>