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 4 3905
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
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
On Mar 23, 2:50 pm, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
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
Chr1s wrote:
On Mar 23, 2:50 pm, Erwin Moller
<since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>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. js*******@attglobal.net
================== This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Arkascha |
last post by:
Maybe someone can give me a short help with this...
I got a server application in a LAMP environment doing batch tasks. A
cronjob serves as a regular trigger, a metronom. The trigged...
|
by: smarty |
last post by:
crontab work every minute
How to execute a tasks if the time is 22:30:45 or 22:31:01
id | time | script
-------------------
4 | 22:31:01 | script0.php
3 | 22:31:00 | script1.php
2 |...
|
by: Frank R. Suchy |
last post by:
Hi,
I want a php-script to maintain (some of) "my" cron jobs.
Therefore it has to modify some crontab.txt (no problem)
and has to execute crontab.
But since php runs as the apache-user it...
|
by: Carl |
last post by:
Hi,
I have this little code snippet that I use for recording audio streams. My
problem is that I want to schedule my recordings with crontab. This does
not work, however. I cannot figure out...
|
by: rbt |
last post by:
How can I safely append a crontab entry to a crontab file
progammatically with Python?
I need to handle crontabs that currently have entries and crontabs that
are empty. Also, I'd like this to...
|
by: David Garamond |
last post by:
I was thinking on how one would design an optimal (performance-wise)
database of large number of schedules with crontab-like semantic. There
will potentially be hundreds of thousands or even...
|
by: Sandman |
last post by:
I have a PHP cli script, that backups my databases, using mysqldump
via system().
When logged in with SSH, and launching the script with "./backup.php",
all works just as it should, but when I...
|
by: roger.moon2 |
last post by:
So I wrote a script and at the top it checks whether a file exists
like below
if (!file_exists("settings.ini"))
return false;
and the crontab entry:
00 08 * * 4 /usr/local/bin/php...
|
by: martijn |
last post by:
H!
I have made a program that is checking if a program is running or not.
If the program is not running then it must start the program again.
in the /etc/crontab:
* * * * ...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |