| 
	
 | 
 Posted by Jerry Stuckle on 03/23/07 22:31 
Chr1s wrote: 
> On Mar 23, 2:50 pm, Erwin Moller 
> <since_humans_read_this_I_am_spammed_too_m...@spamyourself.com> wrote: 
>> Erwin Moller wrote: 
>>> Chr1s wrote: 
>>>> How do I execute a crontab command using php (not CLI) as user Joe? 
>>>> I don't have any problem getting output from commands such as 'ls' 
>>>> using passthru and exec but I am stumped with crontab. 
>>>> Many thanks! 
>>>> Chris 
>>> Hi Chris, 
>>> 1) user Joe: 
>>> If you want user Joe to execute the cronjob, login as use Joe and edit his 
>>> cronjob by typing: 
>>> crontab -e 
>>> Now the contab program opens Joe's cronjobs. 
>>> Most systems open in VI editor, since I hate that thing because I am a 
>>> nOOb, I prefer opening in pico: a small editor that works like a human 
>>> brain, unlike VI (shoot me if you want. :P). 
>>> If you want pico (or nano) too, type first: 
>>> export EDITOR=pico 
>>> then give the crontab -e command. 
>>> 2) shedule 
>>> add a line like this (all on 1 line): 
>>> 0 1 * * * cd /home/yourdir/public_html/ && php -q 
>>> /home/yourdir/public_html/yoursheduledscript.php 
>>> to let the script run each night at 1 o'clock. 
>>> I am not sure about the cd, but had trouble using a script without cd-ing 
>>> to the dir first. 
>>> Hope that helps. 
>>> Good luck. 
>>> Regards, 
>>> Erwin Moller 
>> One addition: when hunting for problems think of the cronjob as: 
>> 1) login as user Joe 
>> 2) Joe gives the commands by hand. 
>> 
>> So if your script isn't doing what you want, you can always try to find what 
>> is wrong by doing excactly the same thing being Joe. 
>> 
>> Good luck. 
>> 
>> Regards, 
>> Erwin Moller- Hide quoted text - 
>> 
>> - Show quoted text - 
>  
> Apologies, I should have been more specific. 
>  
> I want to append to a user's crontab using a php script...not run a 
> script from crontab. 
>  
> For example, 
>  
> exec('crontab MyFile', $var); 
>  
> I don't know how to adapt this code to work for user 'Joe'? 
>  
> Thanks, 
>  
> Chris 
>  
 
Chris, 
 
Then you're going to have to su to user Joe or otherwise have permission  
to open/read/write Joe's crontab.  You can do it with posix_seteuid() or  
posix_setuid() - but these are dangerous - you have to enable the change  
SUID bit for PHP which potentially allows any PHP script to set any  
userid, including root.  Not very safe. 
 
A better way would be to execute a shell script which has permission to  
change the uid and add to the crontab.  This limits your exposure. 
 
--  
================== 
Remove the "x" from my email address 
Jerry Stuckle 
JDS Computer Training Corp. 
jstucklex@attglobal.net 
==================
 
  
Navigation:
[Reply to this message] 
 |