PDA

View Full Version : Dynamic crontab edition from php



dinchu37
May 29th, 2008, 11:32 PM
Hi, i would like to know if is possible to Dynamic edit a crontab file from php, if it's possible can someone tell me how? i searched for this info about 2 days and never got an accuarate answer.

how i'm supposed to give apache access to get the crontab file?

what url i'm supposed to put in the php scrip to open it?

ahmednuaman
May 30th, 2008, 05:59 AM
Normally crontabs are accessed by doing 'crontab -e' in the shell. Now, firstly, who's your crontab running as? Because you'll need to change as them and then access the crontab.

sekasi
May 30th, 2008, 07:46 PM
yes, it's possible. The crontab file is simply a *nix text file; if you can handle serial access files it shouldn't post that big of a problem. Just don't forget to issue a system command to update the Cron file (crontab file_containing_new_info)

GL

dinchu37
May 30th, 2008, 08:21 PM
i have a dedicated server how can I handle serial access files ?
how can i access that file from php?

sekasi
May 30th, 2008, 10:01 PM
Well, um, something like this. Just keep CWD in mind and make sure you do a chown and chmod of the php file and the directory you want to edit so that apache has read/write/execute (7) rights.



<?php
$mynewcron = "0 30 * * * sh /wwwroot/htdocs/stuff/shellscript.sh";
$handle = fopen("/wwwroot/htdocs/stuff/myjob", "a+");
fwrite($handle, "$mynewcron\n");
fclose($handle);
$cronresult = exec("crontab /wwwroot/htdocs/stuff/myjob")
echo $cronresult;
?>

dinchu37
May 30th, 2008, 10:19 PM
i have a dedicated server how can I handle serial access files ?
how can i access that file from php?

sekasi
May 30th, 2008, 10:21 PM
wtf ? I posted example code up there :P

ahmednuaman
May 31st, 2008, 07:54 AM
Lol! Check this out too: http://www.phpclasses.org/browse/file/4272.html

dinchu37
June 3rd, 2008, 03:55 PM
thank you sekasi!

what should i do with current working directory?

dinchu37
June 3rd, 2008, 10:27 PM
thank you sekasi!

what should i do with current working directory?