Results 1 to 2 of 2

Thread: [RESOLVED] Add/Edit/Delete crontab with PHP

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] Add/Edit/Delete crontab with PHP

    I was wondering if anyone knew how to do this? My knowledge in Linux is somewhat limited in this regard.

    Basically I know how to create, edit and delete cron entries using crontab -e, but I want to be able to do this with PHP.

    From what I understand, I'll basically use PHP to generate a crontab file, and then write over the current one (Then I'm guessing some command will have to be run that will tell the OS to update all the cron.daily etc files).

    So in a nut shell, I want to use PHP to write into crontab -e's file. I can figure out the functions on how to manage the entries myself, but just need help with the file.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Add/Edit/Delete crontab with PHP

    Figured it out!

    You can either use a file as such:
    crontab -r #Removes old crontab
    crontab yourNewCronTabFile
    Or you can:
    newLine="* * * * * /path/to/command"
    (crontab -l; echo "$newLine" ) | crontab -
    In PHP:
    Code:
    $newCronTabFile= "###* * * * * /path/to/command";
    shell_exec('crontab -r && line="' . $newCronTabFile . '" && (sudo crontab -l; echo "$line" ) | sudo crontab -');

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width