From 2fe5401e58e0858ccae50b1fd576c19a1748983d Mon Sep 17 00:00:00 2001 From: Megan Watson Date: Mon, 22 Oct 2007 15:22:08 +0000 Subject: [PATCH] KTS-1554 "Implement a Scheduler" Updated. Added a check on the extension to ensure .sh scripts run on *nix and .bat on windows, etc. --- bin/scheduler.php | 57 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/bin/scheduler.php b/bin/scheduler.php index 4997d64..f396e20 100644 --- a/bin/scheduler.php +++ b/bin/scheduler.php @@ -117,24 +117,49 @@ if(!empty($aList)){ $sFreq = $item['frequency']; $sParameters = $item['script_params']; - $iTime = time(); - $iStart = explode(' ', microtime()); - - /* Set up parameters for use by the script - $aParams = explode('|', $sParameters); - - foreach($aParams as $param){ - $aParam = explode('=', $param); - if(!empty($aParam)){ - $$aParam[0] = $aParam[1]; - $sParamList .= "{$aParam[0]} {$aParam[1]} "; + // Check if script is windows or *nix compatible + $extArr = explode('.', $sTaskUrl); + $ext = array_pop($extArr); + $script = implode('.', $extArr); + if(OS_WINDOWS){ + switch($ext){ + case 'sh': + $sTaskUrl = $script.'.bat'; + break; + case 'bin': + $sTaskUrl = $script.'.exe'; + break; + } + }else{ + switch($ext){ + case 'bat': + if(file_exists(KT_DIR . $script.'.sh')){ + $sTaskUrl = $script.'.sh'; + break; + } + // File doesn't exist - log error + $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script}.sh"); + continue; + break; + case 'exe': + if(file_exists(KT_DIR . $script)){ + $sTaskUrl = $script; + break; + } + if(file_exists(KT_DIR . $script.'.bin')){ + $sTaskUrl = $script.'.bin'; + break; + } + // File doesn't exist - log error + $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script} or ".KT_DIR."{$script}.bin"); + continue; + break; } } - */ - - // Run the script as php - //include(KT_DIR . $sTaskUrl); - + + $iTime = time(); + $iStart = explode(' ', microtime()); + // Run the script $file = KT_DIR . escapeshellcmd($sTaskUrl); system("{$file} {$sParameters} >> /dev/null", $retval); -- libgit2 0.21.4