For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > July 2004 > how to run crontab from php skript as a different user









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to run crontab from php skript as a different user
Frank R. Suchy

2004-07-29, 8:55 pm

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 cannot run "my" crontab.

In general: Can a php-script run an external program under a different
user?

Thanx for any advise!
Frank
Daniel Tryba

2004-07-29, 8:55 pm

Frank R. Suchy <usenet@rem.ove-sp.am.ardik.net> wrote:
> Therefore it has to modify some crontab.txt (no problem)
> and has to execute crontab.
>
> But since php runs as the apache-user it cannot run "my" crontab.
>
> In general: Can a php-script run an external program under a different
> user?


Depends on your OS... on unix-like machines you might use sudo to do
this. But a more simple solution is to edit the crontab file from within
php and use the users cron to schedule reloads of the crontab file.

--

Daniel Tryba

Frank R. Suchy

2004-07-30, 3:56 pm

Am Thu, 29 Jul 2004 23:49:36 +0000 (UTC) schrieb Daniel Tryba:

> Frank R. Suchy <usenet@rem.ove-sp.am.ardik.net> wrote:
>
> Depends on your OS... on unix-like machines you might use sudo to do
> this.


Ehm, yepp, it's a Redhat Linux.
But I don't have root access or superuser privileges, so I can't use sudo.
I'm wondering whether there is some tool similar to sudo, which takes user
login and password in the commandline...

> But a more simple solution is to edit the crontab file from within
> php and use the users cron to schedule reloads of the crontab file.


That's exactly what I currently do. But I don't want to reload the file
e.g. every hour just because maybe once in a w there is another job to
be done. But when there is such a job to be added this should happen quite
quickly, reloading the crontab once a day or so would be too seldom...

Frank
Daniel Tryba

2004-07-30, 3:56 pm

Frank R. Suchy <usenet@rem.ove-sp.am.ardik.net> wrote:
>
> Ehm, yepp, it's a Redhat Linux.
> But I don't have root access or superuser privileges, so I can't use sudo.
> I'm wondering whether there is some tool similar to sudo, which takes user
> login and password in the commandline...


su propably can do the job, but not from the commandline... you'd have
to take a look a popen IMHO.

>
> That's exactly what I currently do. But I don't want to reload the file
> e.g. every hour just because maybe once in a w there is another job to
> be done. But when there is such a job to be added this should happen quite
> quickly, reloading the crontab once a day or so would be too seldom...


Have a job that looks for a special file every minute, if file exists
reload the crontab file and than remove special file. If crontab file
gets edited, touch the special file and within a minute the crontab
will be reloaded. Overhead is limited to a file exists test...

--

Daniel Tryba

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com