public static function CronRun($profileID, $in_cron = "N")
 {
     define("path2export", "/bitrix/php_interface/include/catalog_export/");
     $pr = CProfileAdmin::GetByID($profileID)->Fetch();
     $cron_period = intval($pr['PERIOD']);
     $cron_period = $cron_period <= 0 ? 86400 : $cron_period;
     $data = date("d.m.Y H:i:s", $pr['DATA_START']);
     $d = explode(" ", $data);
     $t = explode(":", $d[1]);
     $cron_hour = intval($t[0]);
     $cron_minute = intval($t[1]);
     $cron_hour = $cron_hour <= 0 ? 0 : $cron_hour;
     $cron_minute = $cron_minute <= 0 ? 0 : $cron_minute;
     $cron_php_path = COption::GetOptionString("acrit.googlemerchant", "php_path");
     $cron_php_path = strlen($cron_php_path) > 0 ? $cron_php_path : getPHPExecutableFromPath();
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php")) {
         CheckDirPath($_SERVER["DOCUMENT_ROOT"] . path2export);
         $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php");
         $fp = fopen($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php", "rb");
         $tmp_data = fread($fp, $tmp_file_size);
         fclose($fp);
         $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data);
         $tmp_data = str_replace("#PHP_PATH#", $cron_php_path, $tmp_data);
         $fp = fopen($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php", "w+");
         fwrite($fp, $tmp_data);
         fclose($fp);
     }
     $cfg_data = "";
     if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) {
         $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg");
         $cfg_file_size = $cfg_file_size != 0 ? $cfg_file_size : 1;
         $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb");
         $cfg_data = fread($fp, $cfg_file_size);
         fclose($fp);
     }
     CheckDirPath($_SERVER["DOCUMENT_ROOT"] . path2export . "logs/");
     if ($in_cron == "Y") {
         $cfg_data = preg_replace("#^.*?" . preg_quote(path2export) . "acrit_gm_cron.php " . $profileID . " *>.*?\$#im", "", $cfg_data);
     } else {
         if ($cron_period > 0) {
             $strTime = "0 */" . $cron_period . " * * * ";
         } else {
             $strTime = intval($cron_minute) . " " . intval($cron_hour) . " * * * ";
         }
         if (strlen($cfg_data) > 0) {
             $cfg_data .= "\n";
         }
         $cfg_data = preg_replace("#^.*?" . preg_quote(path2export) . "acrit_gm_cron.php " . $profileID . " *>.*?\$#im", "", $cfg_data);
         $cfg_data .= $strTime . $cron_php_path . " -f " . $_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php " . $profileID . " >" . $_SERVER["DOCUMENT_ROOT"] . path2export . "logs/" . $profileID . ".txt\n";
     }
     CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/");
     $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data);
     $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb");
     fwrite($fp, $cfg_data);
     fclose($fp);
     $arRetval = array();
     @exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var);
 }
    // create array of IP addresses (if they do not already exist!)
    if (!checkDuplicate(transform2long($subnet['subnet'] + $m), $_POST['subnetId'])) {
        $ip[] = $subnet['subnet'] + $m;
    }
}
# create 1 line for $argv
// <eNovance>
// Print a message if no host is found then exit
if (count($ip) == 0) {
    print "<div class='alert alert-info'>All host already listed</div>";
    exit;
}
// </eNovance>
$ip = implode(";", $ip);
# get php exec path
$phpPath = getPHPExecutableFromPath();
# set script
$script = dirname(__FILE__) . '/../../../functions/scan/' . $_REQUEST['pingType'] . 'Script.php';
# invoke CLI with threading support
$cmd = "{$phpPath} {$script} '{$ip}'";
# save result to $output
exec($cmd, $output, $retval);
# format result - alive
$alive = json_decode(trim($output[0]));
# if not numeric means error, print it!
if (!is_numeric($alive[0])) {
    $error = $alive[0];
}
#verify that pign path is correct
if (!file_exists($pathPing)) {
    $pingError = true;
/* required functions */
require_once '../../../functions/functions.php';
require_once dirname(__FILE__) . '/../../../functions/scan/config-scan.php';
/* verify that user is logged in */
isUserAuthenticated(true);
/* verify that user has write permissions for subnet */
$subnetPerm = checkSubnetPermission($_REQUEST['subnetId']);
if ($subnetPerm < 2) {
    die('<div class="alert alert-danger">' . _('You do not have permissions to modify hosts in this subnet') . '!</div>');
}
# verify post */
CheckReferrer();
# get subnet details
$subnet = getSubnetDetailsById($_POST['subnetId']);
# get php exec path
if (!($phpPath = getPHPExecutableFromPath())) {
    die('<div class="alert alert-danger">Cannot access php executable!</div>');
}
# set script
$script = dirname(__FILE__) . '/../../../functions/scan/scanIPAddressesScript.php';
# invoke CLI with threading support
$cmd = "{$phpPath} {$script} 'discovery' '" . transform2long($subnet['subnet']) . "/{$subnet['mask']}' '{$_POST['subnetId']}'";
# save result to $output
exec($cmd, $output, $retval);
# die of error
if ($retval != 0) {
    print "<div class='alert alert-danger'>Error executing scan! Error code - {$retval}</div>";
    if ($_POST['debug'] == 1) {
        print "<pre>";
        print_r($output);
        print "</pre>";