473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Execute crontab as user Joe using php...

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

Mar 23 '07 #1
4 3943
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
Mar 23 '07 #2
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
Mar 23 '07 #3
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

Mar 23 '07 #4
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
==================
Mar 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
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...
4
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 |...
3
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...
4
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...
3
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...
2
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...
3
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...
5
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...
2
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: * * * * ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.