Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: simulate next event #94

Open
alanbork opened this issue Sep 21, 2021 · 1 comment
Open

feature: simulate next event #94

alanbork opened this issue Sep 21, 2021 · 1 comment

Comments

@alanbork
Copy link

alanbork commented Sep 21, 2021

When writing new cron files it's often nice to see what will actually happen when the next event in the crontab is reached. As far as I can tell there's no "simulation" option to make this happen.

What I propose is a new command line argument that requests that cron run any command(s) that would be due to execute at that precise moment in time, like this: cron --simulate . If you leave out it just runs the next command due to occur, and also prints the timestamp for the next even that would follow that one. Thus, if you wanted to simulate several events in a row, you would first do

cron --simulate
next task occurs in 3 hours and 5 minutes:
[next, the command would be run and the result sent to stdout]

and then finally cron would print
next event would be 2 days, 5 hours, and 1 minute later, at timestamp 341414211

this would allow you to continue the chain as far as you wanted.

obviously this would only run the events in the current user's crontab.

it might be nice to have the option of just printing out what the command would be, in addition to the option of actually executing the command. you could make that an interactive choice, since obviously this is not a feature that would be of use in scripts.

@ferdnyc
Copy link

ferdnyc commented May 30, 2022

it might be nice to have the option of just printing out what the command would be, in addition to the option of actually executing the command

Yeah, in fact I don't love the idea of anything initiated by a --simulate flag actually executing anything, since to my mind --simulate sounds awfully close to --dry-run or other, similar flags that mean, "explain, DON'T do". I would expect a crontab --simulate to display some information, without anything being run.

(And, really, it can't be a "proper" simulation, because the crontab command is running in your user session. Whereas when Cronie starts jobs from the user crontab, they're run in a very different process environment. So, that makes any such simulation inherently flawed.)

The idea of explaining what would be executed and when, that part's great. I'm all for that!

Edit: (I was going to suggest that a method of simulating actual runs of the crontab entries would be to run at now <the command used for the entry>, but now I see that at is completely separate from and unrelated to Cronie, so I guess that wouldn't be an accurate simulation either.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants