0

I'm currently programming a web interface in PHP (5.3) for handling timings and installing cronjobs as a simple interface for managing cronjobs. The web server is on the same server as the cron service. I've managed to save the crontab to a file to exchange it for a specific user on the system. Now I have the problem that php is running with a different user than the crontab should be installed for. In addition I need to be able to define the cron-user in my web interface via an input field.

I've tried to execute a shell command via PHP crontab -u MyCronuser MyCrontab but the PHP user does not have privileges for using -u parameter (and I'm not allowed to change this) So next thought was to do something like su cronUser but there is no -p parameter so I cannot handle over the password for login. I tried to chain the commands like su cronuser && echo 'MyPassword' but it didn't work and I did not find any solution via Google for logging into shell with different users with PHP. Is there a way for doing so? Using sudo for performing as root user without password is also not an option since I'm not allowed to activate these permissions.

Is there any solution I might have missed? Maybe a different approach to my issue?

1 Answer 1

0

This answer falls under the different approach category and might not be helpful for you. I have built several cron systems that operate in the following manner.

1) Setup a cron to run every minutes and call a php file (for example cron.php) 2) cron.php will pull data from a database table that indicates what scripts need to run and at what interval 3) cron executes the appropriate scripts - handles errors etc.

I'm not sure what your need is for users but it should be trivial to add that data to the database table.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks für your answer. So you would suggest some kind of virtual cron-service? But what about speed and resources if you have a php script every minute which reads database tables and run scripts? Do you have any experience with that? And what if 2 or more jobs are at the same time? With just one php cronjob this is not possible to handle, one would be after the second stoped.
Overhead has never been an issue at all. If it was you could cache the database values and have them update every day. In my code I prefer to only have one script running at a time but it is trivial to allow multiple to run : stackoverflow.com/questions/4646788/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.