Re: [請益] shell_exec的疑問

看板PHP作者 (閒泡菜)時間15年前 (2010/03/16 22:20), 編輯推噓1(103)
留言4則, 2人參與, 最新討論串4/4 (看更多)
我有努力的更改程式了 也成功在主機新增一次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

03/18 01:29, , 1F
cat /etc/crontab | sed '/index.php/d' > /tmp/file
03/18 01:29, 1F

03/18 17:35, , 2F
這麼做並沒有更改到/etc/crontab裡面的內容而是用cat
03/18 17:35, 2F

03/18 17:38, , 3F
將有index.php的字串給刪除然後導入別的地方
03/18 17:38, 3F

03/18 17:39, , 4F
可是/etc/crontab裡 那些index.php還是在耶@@"
03/18 17:39, 4F
※ 編輯: s66449 來自: 114.27.189.59 (03/18 17:39)
文章代碼(AID): #1BdvEIJS (PHP)
文章代碼(AID): #1BdvEIJS (PHP)