问题
I want to create a cron job which will run with the user define time in database. For eg.User can set start time and end time in the database .When the end time is reached I want cron to trigger one script to send mail.First of all Is it possible in cron or I have to go with some different approach ? and this all things will be done on AWS EBS. Below is what I tried on my local machine to just send a simple mail which is too basic
*/1 * * * * /usr/bin/php -q/var/www/html/cronTry/cron.php
回答1:
You dont want to run the CRON every minute instead create a specific job for your user and run it once. Something like this should work (untested - on mobile)
$your_users_date;
$cmd = "sudo crontab -l | { cat; echo ". date("i H d m",strtotime($your_users_date))." * php /path_to_your_script.php arg1 arg2; } | crontab -";
shell_exec($cmd);
This will append a job to the crontab at the time your user has defined
回答2:
Get the dynamic details from the database, create the command string and
You can easily run your cron by passing the command in the shell_exec()
来源:https://stackoverflow.com/questions/28293365/create-a-cron-job-with-user-define-dtime