how to run crontab from php skript as a different user

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank R. Suchy

    how to run crontab from php skript as a different user

    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

    #2
    Re: how to run crontab from php skript as a different user

    Frank R. Suchy <usenet@rem.o ve-sp.am.ardik.net > wrote:[color=blue]
    > 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?[/color]

    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

    Comment

    • Frank R. Suchy

      #3
      Re: how to run crontab from php skript as a different user

      Am Thu, 29 Jul 2004 23:49:36 +0000 (UTC) schrieb Daniel Tryba:
      [color=blue]
      > Frank R. Suchy <usenet@rem.o ve-sp.am.ardik.net > wrote:[color=green]
      >> 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?[/color]
      >
      > Depends on your OS... on unix-like machines you might use sudo to do
      > this.[/color]

      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...
      [color=blue]
      > 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.[/color]

      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 week 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

      Comment

      • Daniel Tryba

        #4
        Re: how to run crontab from php skript as a different user

        Frank R. Suchy <usenet@rem.o ve-sp.am.ardik.net > wrote:[color=blue][color=green]
        >> Depends on your OS... on unix-like machines you might use sudo to do
        >> this.[/color]
        >
        > 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...[/color]

        su propably can do the job, but not from the commandline... you'd have
        to take a look a popen IMHO.
        [color=blue][color=green]
        >> 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.[/color]
        >
        > 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 week 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...[/color]

        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

        Comment

        Working...