I am trying to create a PHP file, which will run a Linux command, and email the results to me. Then I will schedule the file to be executed via cron. I have already tested the command - grep “fail” /var/log/syslog | awk ‘{ print $9 }’ | sort | uniq -c - and it works perfectly. This is on a mail server running qmail.
Then to test it, I run wget “https://xxx.xxx.xxx.xxx/cron/send_mail_failures.php” --no-check-certificate > /dev/null
The test seems to output everything normally, but I never get the email. I know the credentials for the mail account are correct, as we use this for other things. I replaced the ip and password with xxx.
Here is my code:
[php]
<? include_once("mail.inc.php"); $temp = ""; extract($_REQUEST,EXTR_PREFIX_ALL,"r"); ob_start(); //$output = cat /var/log/qmhandle_output | grep "Deleting" | awk '{ print $1,$2 }' | sort | uniq -c; $output = grep "fail" /var/log/syslog | awk '{ print $9 }' | sort | uniq -c; qob_end_clean(); //echo $output; if (!empty($output)) { $mail = new my_phpmailer; $mail->IsHTML(false); $mail->SMTPAuth = true; $mail->Host = "xxx.xxx.xxx.xxx"; $mail->Username = "[email protected]"; $mail->Password = "xxxxxx"; $mail->SMTPDebug = false; $mail->From = "[email protected]"; $mail->Subject = "(MAIL) qmHandle Failure Report"; $mail->Body = $output; $mail->AddAddress("[email protected]"); if($mail->Send()) { } else { } } ?>[/php]