473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 17 '05 #1
3 5355
Frank R. Suchy <us****@rem.o ve-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

Jul 17 '05 #2
Am Thu, 29 Jul 2004 23:49:36 +0000 (UTC) schrieb Daniel Tryba:
Frank R. Suchy <us****@rem.o ve-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.


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 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
Jul 17 '05 #3
Frank R. Suchy <us****@rem.o ve-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...


su propably can do the job, but not from the commandline... you'd have
to take a look a popen IMHO.
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 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...


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

Jul 17 '05 #4

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

Similar topics

2
3538
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 processcollects a number of pending jobs to be run and typically creates a number of additional jobs to be run in future. The type of created jobs, their parameters and everything can be configured in the application. Fine... In addition I'd like to...
2
2167
by: schwerdy | last post by:
Greetings to all Python fans :-) Is it possible to create a skript, that can read from a unix pipe (eg.: "find -type f -name "*.ogg" | myscript.py"), _AND_ interact with the user by waiting for keypress (eg.: getkey() funktion of a curses screen)? My tests failed: When I divert data via pipe to my skript and do sys.stdin.read(), screen.getkey() always returns -1.
3
5393
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 work across Linux and BSD systems. Any pointers?
2
8421
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 millions of "crontab" entries, and there will be a query run once every minute to determine which entries are to be run for that minute. The primary goal is, of course, for the query to run as fast as possible. My first stab is, straightforward...
3
3375
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 put it in a crontab: 00 2 * * * /home/sandman/bin/backup.php I get a mail that says:
4
3966
by: Chr1s | last post by:
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
2
3870
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: * * * * * root /usr/sbin/ program_prgchk in the /usr/sbin/program_prgchk:
3
1559
by: noama | last post by:
Hi, I'm using a computer with a Linux CentOS Operating system, which uses python 2.3 and known to break if python is upgraded to 2.5. Since i need to run 2.5 scripts on that machine, some people in a linux forum recommended to compile 2.5 on that machine and have two python interpreters installed. so now, when i type "python" i still get the 2.3 version, and when i type "python2" i get the new version. to make sure it works i created a simple...
0
1345
by: Martin Marcher | last post by:
Hello, is anyone aware of a crontab library. Possibly even more complete, something that will let me create/manipulate/delete crontab entries in a nice way and install the new crontab accordingly. I had a look at the crontab docs and never realized how complex it actually is. So before I spend time in creating such a thing maybe
0
8063
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8498
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8478
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.