Create a cron job with user define dtime

前提是你 提交于 2019-12-12 03:16:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!