This is the file I try to exec in a cron job.
The call
php -f backup.php
return right away with no action?
but
php -r "echo shell_exec('/sbin/affa --run prodserv');"
works fine?
<?php
// /home/e-smith/files/users/admin/home/backup.php
include_once("phpmailer/class.phpmailer.php");
function isCli()
{
$sapiname = php_sapi_name();
if((substr($sapiname , 0, 3) == 'cgi') || (substr($sapiname , 0, 3) == 'cli')) // PHP 4 and 5 version
if(empty($_SERVER['REMOTE_ADDR']))
{
return true;
}
return false;
}
function mailoutput($to, $mailbody)
{
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetLanguage("en");
$mail->IsHTML(true);
$mail->FromName = "noreply@beast.dk";
$mail->From = $mail->FromName;
$mail->Subject = "Backup server log";
$mail->WordWrap = 50;
$mail->MsgHTML($mailbody);
$mail->AltBody = strip_tags(preg_replace("/<br>/", "\r\n", $mailbody));
$mail->AddAddress($to);
if(!$mail->Send())
{
die("Mail Error: " . $mail->ErrorInfo);
}
}
$parameters = $_SERVER['argv'];
$mailbody = "<h2>Backup server log</h2>";
//sleep(120);
$starttime = time();
$returnstr = shell_exec("/sbin/affa --run prodserv");
$execmin = (time() - $starttime)/60;
if(strlen($returnstr))
$mailbody .= $returnstr;
else
$mailbody .= "<br>Backup performed to backupserver in ".$execmin." minutes";
$returnstr = shell_exec("/sbin/affa --list-archives");
if(strlen($returnstr))
$mailbody .= "<br><br>".nl2br($returnstr);
if(isCli())
{
foreach($parameters as $key => $value)
{
if($key > 0)
mailoutput($value, $mailbody);
}
}
else
{
if(isset($_GET['email']))
mailoutput($_GET['email'], $mailbody);
}
//shell_exec("/sbin/shutdown -h +15");
?>