Commit 26fbbb0f authored by Franco Fichtner's avatar Franco Fichtner

cron: remove short-lived empty cron, this is better...; #911

parent eaabe7f4
...@@ -2371,11 +2371,11 @@ function configure_cron() ...@@ -2371,11 +2371,11 @@ function configure_cron()
$autocron = array(); $autocron = array();
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 sshlockout', '*/60');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout', '*/60'); $autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 webConfiguratorlockout', '*/60');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 sshlockout', '*/60');
$autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 virusprot', '*/60'); $autocron[] = generate_cron_job('/usr/local/sbin/expiretable -v -t 3600 virusprot', '*/60');
$autocron[] = generate_cron_job('/usr/local/etc/rc.dyndns.update', '1', '1');
$autocron[] = generate_cron_job('/usr/local/etc/rc.update_urltables', '30', '12'); $autocron[] = generate_cron_job('/usr/local/etc/rc.update_urltables', '30', '12');
$autocron[] = generate_cron_job('/usr/local/etc/rc.dyndns.update', '1', '1');
if (!empty($config['system']['rrdbackup'])) { if (!empty($config['system']['rrdbackup'])) {
$autocron[] = generate_cron_job('/usr/local/etc/rc.backup_rrd', '0', '*/' . $config['system']['rrdbackup']); $autocron[] = generate_cron_job('/usr/local/etc/rc.backup_rrd', '0', '*/' . $config['system']['rrdbackup']);
...@@ -2416,26 +2416,11 @@ function configure_cron() ...@@ -2416,26 +2416,11 @@ function configure_cron()
break; break;
} }
$anchor = '# custom crontab entries'; $crontab_contents = "# DO NOT EDIT THIS FILE -- OPNsense auto-generated file\n";
$crontab_contents .= "# Please use /etc/crontab for your overrides instead.\n";
/* preserve existing crontab entries */ $crontab_contents .= "SHELL=/bin/sh\n";
$crontab_contents = file('/etc/crontab', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $crontab_contents .= "PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin\n";
$crontab_contents .= "#minute\thour\tmday\tmonth\twday\tcommand\n";
for ($i = 0; $i < count($crontab_contents); $i++) {
$cron_item = &$crontab_contents[$i];
if (strpos($cron_item, $anchor) !== false) {
array_splice($crontab_contents, $i - 1);
break;
}
}
/* please maintain the newline at the end of file */
$crontab_contents = implode("\n", $crontab_contents) . "\n";
$crontab_contents .= "#\n";
$crontab_contents .= $anchor . "\n";
$crontab_contents .= '# auto-generated at ' . date('F j, Y, g:i a') . "\n";
$crontab_contents .= "#\n";
foreach ($autocron as $item) { foreach ($autocron as $item) {
$crontab_contents .= "{$item['minute']}\t"; $crontab_contents .= "{$item['minute']}\t";
...@@ -2443,22 +2428,14 @@ function configure_cron() ...@@ -2443,22 +2428,14 @@ function configure_cron()
$crontab_contents .= "{$item['mday']}\t"; $crontab_contents .= "{$item['mday']}\t";
$crontab_contents .= "{$item['month']}\t"; $crontab_contents .= "{$item['month']}\t";
$crontab_contents .= "{$item['wday']}\t"; $crontab_contents .= "{$item['wday']}\t";
$crontab_contents .= "{$item['who']}\t";
$crontab_contents .= "{$item['command']}\n"; $crontab_contents .= "{$item['command']}\n";
} }
$crontab_contents .= "#\n"; file_put_contents('/var/cron/tabs/root', $crontab_contents);
$crontab_contents .= "# If possible do not add items to this file manually.\n";
$crontab_contents .= "# If you do so, this file must be terminated with a blank line (e.g. new line)\n";
$crontab_contents .= "#\n\n";
file_put_contents('/etc/crontab', $crontab_contents);
unset($crontab_contents);
killbypid('/var/run/cron.pid', 'HUP'); killbypid('/var/run/cron.pid', 'HUP');
} }
function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*', $month = '*', $weekday = '*', $who = 'root') function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*', $month = '*', $weekday = '*')
{ {
$cron_item = array(); $cron_item = array();
...@@ -2467,7 +2444,6 @@ function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*' ...@@ -2467,7 +2444,6 @@ function generate_cron_job($command, $minute = '0', $hour = '*', $monthday = '*'
$cron_item['mday'] = $monthday; $cron_item['mday'] = $monthday;
$cron_item['month'] = $month; $cron_item['month'] = $month;
$cron_item['wday'] = $weekday; $cron_item['wday'] = $weekday;
$cron_item['who'] = $who;
$cron_item['command'] = $command; $cron_item['command'] = $command;
return $cron_item; return $cron_item;
......
empty.cron:/var/cron/tabs/root
user.cron:/var/cron/tabs/nobody user.cron:/var/cron/tabs/nobody
# DO NOT EDIT THIS FILE -- OPNsense auto-generated file
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
# This file is empty on purpose, use /etc/crontab for overrides
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment