tags:

views:

41

answers:

3

i have 10 users. and i want to set a cron for that 10 users. Now when a perticular user logged in he can set the corn time from his panel and cron will run at that time .Also when new user added a new cron will be set for that user with default time according to application.

how can i achieve this?

A: 

This sounds generally like a very unwise thing to do, but if you know what you're doing and understand the security problems involved etc. I would suggest solving this using two scripts

  • one php part which lets the user view his crontab and manipulate time settings using an html form and storing the wanted changes in a known place on your system.
  • one shell script part running as a trusted user on your system picking up the changes at a given interval (once a minute maybe) and doing the actual updates to cron.

Adding stuff to cron is potentially a very dangerous thing and only very trusted users should be allowed to do so. Any web solution should be regarded as insecure and you should take extra care to make sure any input is properly audited.

thomasmalt
good, but not a solution
phirschybar
I don't see why you felt the need to vote it down though.
thomasmalt
@phirschybar Also what you're suggesting is **almost exactly** the same think I was suggesting, only you're using a database to store the changes, but I suggest "somewhere on the system", which could be a database, or a file or something else, and actually updating the crontab of each user after the input is properly vetted.
thomasmalt
how can i set or update a crontab through php script
+1  A: 

I agree with thomasmalt that it is not wise but what you should do instead is have it so your users can set a cron time in a 'users' database table (like mysql) with columns: 'interval (INT)' and 'last_update (DATETIME)'. So every user has their own time set. Then you decide what is the lowest increment you will allow (such as 1 minute) and only let your users set times higher than that.

Then you run a cron every 1 minute which checks the 'users' table. Find any users where interval is less than or equal to the time since 'last_update'. Then run your actions for those users. This effectively does the same thing as setting crons for every user.

phirschybar
please may you describe in detail if have some code or demo
+1 @phirschybar good solution.
Imran Naqvi
I don't have any code off hand that would apply to this because I don't know the specifics of the application. This is just a theoretical alternative to letting the users create the cron jobs on the system.
phirschybar
A: 

As thomasmalt said this is probably not wise to do in a public system ... you don't want to let users mess with system crons.

I suggest you let the users specify a time of day in their controlpanel and have a cron script run every minute. In that script it's easy enough to fetch the users that match the current time and execute their script. It achieves the same thing, is a little more verbose and more to code but alot more secure.

ChrisR