作者s66449 (閒泡菜)
看板PHP
標題Re: [請益] shell_exec的疑問
時間Tue Mar 16 22:20:00 2010
我有努力的更改程式了
也成功在主機新增一次cron指令了
可是有點小問題
因為我每次按一次button去掃描
就新增一次cron指令
要是新增兩次的話就兩個cron指令
請問可以用什麼函數可以把前一次打的
cron指令給覆寫掉呢??
下面是程式碼
if ($_POST['ScanTime'])
{
$tmp_cron_file = '/tmp/crontab.tmp';
$time=$_POST["TimeArea"];
$cron .= "*/$time * * * * /usr/bin/php -q /var/www/html/nmap/index.php\n";
file_put_contents("/etc/crontab", $cron,FILE_APPEND);
shell_exec('./run /etc/rc.d/init.d/crond restart');
}
例如我第一次輸入的時間是10
第二次輸入時間的5
之後我在linux主機上用cat去查
[root@L1006 ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
*/10 * * * * /usr/bin/php -q /var/www/html/nmap/index.php
*/5 * * * * /usr/bin/php -q /var/www/html/nmap/index.php
如何有辦法把第一次的10分鐘給覆蓋掉呢??
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.27.190.177
推 appleboy46:cat /etc/crontab | sed '/index.php/d' > /tmp/file 03/18 01:29
→ s66449:這麼做並沒有更改到/etc/crontab裡面的內容而是用cat 03/18 17:35
→ s66449:將有index.php的字串給刪除然後導入別的地方 03/18 17:38
→ s66449:可是/etc/crontab裡 那些index.php還是在耶@@" 03/18 17:39
※ 編輯: s66449 來自: 114.27.189.59 (03/18 17:39)