程式碼:存成網頁cronjobs.php
<?php
if ($_REQUEST['action'] == 'save') {
$out='';
for($r=1;$r<=$_REQUEST['rows'];++$r)
if ($_REQUEST['r'.$r.'c0']!='') for($c=0;$c<7;++$c) $out.=$_REQUEST['r'.$r.'c'.$c].($c<6?chr(9):chr(10));
file_put_contents('/etc/crontab', $out);
exec('killall crond;crond');
}
$filearray=file('/etc/crontab');
$_REQUEST['action'] == '';
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>cronjobs</title>
<style>body,input{font:12px Arial;margin-right:1px;margin-bottom:1px}h3{font-family:Arial}
body{background-color:#ddf}</style>
<script>
function mark(r) {
var e=document.getElementsByName(r+'c0')[0];
if (e.value.charAt(0)=='#')
for (var i=0;i<7;++i) document.getElementsByName(r+'c'+i)[0].style.color='#444';
else
for (var i=0;i<7;++i) document.getElementsByName(r+'c'+i)[0].style.color='#090';
}
</script>
</head><body><h3>CronJobs</h3>
<form method="post" action="cronjobs.php">
<input type="hidden" id="action" name="action" value="">
<?php
$r=0;
foreach($filearray as $rec) {
$r++; $c=0;$f=explode(chr(9),$rec);
print '<input title="*|0..59: 8 1,3,5 2-5 * */2" name="r'.$r.'c0" type="text" size="8" '.($r==1?'readonly':'').' value="'.$f[0].'"/>';
print '<input title="*|0..23: 8 1,3,5 2-5 * */2" name="r'.$r.'c1" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[1].'"/>';
print '<input title="*|1..31: 8 1,3,5 2-5 * */2" name="r'.$r.'c2" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[2].'"/>';
print '<input title="*|1..12: 8 1,3,5 2-5 * */2" name="r'.$r.'c3" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[3].'"/>';
print '<input title="*|0..7: so=0/7 sa=6" name="r'.$r.'c4" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[4].'"/>';
print '<input name="r'.$r.'c5" type="text" size="7" '.($r==1?'readonly':'').' value="'.$f[5].'"/>';
print '<input name="r'.$r.'c6" type="text" size="40" '.($r==1?'readonly':'').' value="'.$f[6].'"/>';
if ($r>1) {
print '<script>mark("r'.$r.'")</script>';
?>
<input type="button" value="X" title="delete"
onclick="for (var i=0;i<7;++i) document.getElementsByName('r<?php print $r ?>c'+i)[0].value=''"/>
<input type="button" value="#" title="activate / deactivate"
onclick="var v=document.getElementsByName('r<?php print $r ?>c0')[0];
if (v.value.charAt(0)!='#') v.value='#'+v.value;else v.value=v.value.substring(1); mark('r<?php print $r ?>')"/>
<?php }
print '<br/>';
}
$rmax=2+$r++;
for($r;$r<=$rmax;$r++) {
print '<input title="*|0..59: 8 1,3,5 2-5 * */2" name="r'.$r.'c0" type="text" size="8" value=""/>';
print '<input title="*|0..23: 8 1,3,5 2-5 * */2" name="r'.$r.'c1" type="text" size="7" value=""/>';
print '<input title="*|1..31: 8 1,3,5 2-5 * */2" name="r'.$r.'c2" type="text" size="7" value=""/>';
print '<input title="*|1..12: 8 1,3,5 2-5 * */2" name="r'.$r.'c3" type="text" size="7" value=""/>';
print '<input title="*|0..7: so=0/7 sa=6" name="r'.$r.'c4" type="text" size="7" value=""/>';
print '<input name="r'.$r.'c5" type="text" size="7" value=""/>';
print '<input name="r'.$r.'c6" type="text" size="40" value=""/>';
?>
<input type="button" value="X" title="delete"
onclick="for (var i=0;i<7;++i) document.getElementsByName('r<?php print $r ?>c'+i)[0].value=''"/>
<input type="button" value="#" title="activate / deactivate"
onclick="var v=document.getElementsByName('r<?php print $r ?>c0')[0];
if (v.value.charAt(0)!='#') v.value='#'+v.value;else v.value=v.value.substring(1); mark('r<?php print $r ?>')"/><br/>
<?php } ?>
<input type="hidden" name="rows" value="<?php print --$r ?>"/>
<input type="button" value="save /etc/crontab & restart crond" style="margin-top:6px"
onclick="document.getElementById('action').value='save';submit()"/>
</form></body></html>
執行後可以執行程式,會讀取/etc/crontab,修改後按「save /etc/crontab & restart crond」存檔。
用ssh程式進入,用root帳號進入,執行下面程式:就可以完成cron排程
/usr/syno/etc/rc.d/S04crond.sh stop
/usr/syno/etc/rc.d/S04crond.sh start