ginerjm Posted September 6, 2021 Share Posted September 6, 2021 Has anyone managed to create a cron job on their hosted domain from a running script? I have a task that I do repeatedly and I would like to run a quick script that records the happening of that task and that then posts a new cron job to execute at a certain time to remind me via an email or text message. That latter part I have written. It is just the creating of the cron job that I am asking about. Setting it up via my cpanel is just a pia and not something I am going to even consider. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/ Share on other sites More sharing options...
requinix Posted September 6, 2021 Share Posted September 6, 2021 Create one cronjob (manually) that decides whether or not it needs to execute. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589699 Share on other sites More sharing options...
ginerjm Posted September 6, 2021 Author Share Posted September 6, 2021 That's the thing I'm trying to avoid. That means having an hourly(?) execution to check a table(?) for some indication to do what needs to be done. A lot of wasted executions. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589700 Share on other sites More sharing options...
requinix Posted September 6, 2021 Share Posted September 6, 2021 It's only hourly. That's nothing. Your alternative of dynamically creating cronjobs is... weird, like, it feels really weird. Cron isn't designed for one-off tasks like that. I'm not even sure why you (think you) need cron for this in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589701 Share on other sites More sharing options...
ginerjm Posted September 6, 2021 Author Share Posted September 6, 2021 I try to avoid the unnecessary. If I know when I need the task to run I"m trying to make that happen. Thanks for the help tho... Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589702 Share on other sites More sharing options...
requinix Posted September 6, 2021 Share Posted September 6, 2021 You would be trading a negligible amount of resources to run your script unnecessarily for a lot less complexity. What's worth more to you: having to juggle cronjobs according to when you need them and when you don't, or always running some script that has a couple lines of logic that detect whether it needs to run? Also consider that this "always schedule and stop running if unnecessary" is extremely common. It's so much easier and there is virtually no downside at all to having it in there. Trying to manage the cronjob is a micro-optimization that comes with a lot of complexity. How long have you already spent trying to solve this problem? How much more time would it take to implement and troubleshoot it? It's just not worth your time. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589703 Share on other sites More sharing options...
ginerjm Posted September 6, 2021 Author Share Posted September 6, 2021 The cron job would be triggered by an app I already have. When I run that quickie to post an activity my plan is to setup the one-time cron job to run at a specific time later on and that's it. No juggling here and not very complex. I put in a little bit of time researching how to do this. Then I decided to ask around. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589704 Share on other sites More sharing options...
kicken Posted September 7, 2021 Share Posted September 7, 2021 The complexity here come from trying the add/remove your one-time cron jobs. Cron isn't really designed for this type of usage so making it work this way would take a fair bit more effort on your part than doing the traditional way. Have you considered using at rather than cron? It seems to fit your scenario better. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589710 Share on other sites More sharing options...
ginerjm Posted September 7, 2021 Author Share Posted September 7, 2021 What is "at"? Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589718 Share on other sites More sharing options...
dodgeitorelse3 Posted September 7, 2021 Share Posted September 7, 2021 Click the "at" in his reply Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589719 Share on other sites More sharing options...
ginerjm Posted September 7, 2021 Author Share Posted September 7, 2021 I don't do linux so this means nothing to me. Anyway - my host does not provide any interface to cpanel and its cron feature so this idea is not possible. Thanks for the input people. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589721 Share on other sites More sharing options...
Barand Posted September 7, 2021 Share Posted September 7, 2021 Windows has an AT command as its method of running cron jobs. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589722 Share on other sites More sharing options...
Solution ginerjm Posted September 7, 2021 Author Solution Share Posted September 7, 2021 The original idea was to have my php script do this thing. I have no access to do windows things on my host's server which is probably not a windows one. Anyway - I think we've beat this topic to death. Quote Link to comment https://forums.phpfreaks.com/topic/313674-cron-jobs/#findComment-1589723 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.