News for hackers. Stuff that matters.
Re:OpenBSD cron(8) now supports random ranges with steps by g0xA52A2A on Monday May 08, 2023 @01:25PM (#35864382)
Another nicety OpenBSD's cron gained not long ago was the "-s" flag to ensure only a single instance of command will be run concurrently.

https://man.openbsd.org/man5/crontab.5#s

Re:OpenBSD cron(8) now supports random ranges with steps by hnlmorg on Monday May 08, 2023 @01:55PM (#35864802)
Today I learned the -n flag. Is this also an OpenBSD exclusive?

I have to say, these flags are a really nice enhancement to cron.

Re:OpenBSD cron(8) now supports random ranges with steps by networked on Monday May 08, 2023 @03:34PM (#35866032)
Re:OpenBSD cron(8) now supports random ranges with steps by pengaru on Monday May 08, 2023 @02:05PM (#35864946)
That's gross. If the operation shouldn't run concurrently it should use an exclusive flock or similar. It's not just cron that can cause concurrent execution, and if that matters you generally want to robustly prevent it - not just if cron is the executor.
Re:OpenBSD cron(8) now supports random ranges with steps by thiagocsf on Monday May 08, 2023 @02:23PM (#35865176)
It’s not gross. It’s a simple solution to a simple and common cron problem

Just because it doesn’t consider external executions, it doesn’t mean it’s a bad solution. Horses for courses etc

Re:OpenBSD cron(8) now supports random ranges with steps by pengaru on Monday May 08, 2023 @02:28PM (#35865245)
> It’s not gross. It’s a simple solution to a simple and common cron problem

No, it's gross. By providing that facility in the wrong place it discourages implementing it in the right place to people who come at the problem from the cron perspective.

Wrap the command in a flock-running script. That script goes in the crontab entry. When you're inevitably debugging your cron-scheduled command - paydirt! The command serializes itself still while you're manually testing instead of shitting itself.

Re:OpenBSD cron(8) now supports random ranges with steps by eska on Monday May 08, 2023 @03:26PM (#35865937)
Isn’t that the same? Just because you check a file lock in your script doesn’t mean that other invocations of the program without the script will check the lock.
Re:OpenBSD cron(8) now supports random ranges with steps by pengaru on Monday May 08, 2023 @03:36PM (#35866049)
No, it's not the same. The crontab entry reflects what you'd run to reproduce what the crontab does.
Re:OpenBSD cron(8) now supports random ranges with steps by eska on Tuesday May 09, 2023 @08:52AM (#35873606)
Ok, but your original criticism stated that solving this in cron is bad because the program may be run outside of cron:

* It's not just cron that can cause concurrent execution, and if that matters you generally want to robustly prevent it - not just if cron is the executor.*

So you did not like that exclusion only worked when triggered from cron. But in your case it also only works when triggered from your script. So cron just made your script an integrated feature and you’re essentially criticizing your own solution.

Re:OpenBSD cron(8) now supports random ranges with steps by Apofis on Monday May 08, 2023 @05:51PM (#35867475)
Lock files in scripts are actually pretty unreliable, learned this the really hard way and the lesson cost $10's of thousands of dollars.
Re:OpenBSD cron(8) now supports random ranges with steps by r3trohack3r on Monday May 08, 2023 @09:03PM (#35869020)
Surprised to see this, mind sharing the experience?

How did the lock fail? Was there a more reliable fix?

Re:OpenBSD cron(8) now supports random ranges with steps by mjw1007 on Monday May 08, 2023 @02:39PM (#35865391)
I think it's fine for the case where running the operation more than once at a time isn't incorrect, but potentially wastes resources.
Re:OpenBSD cron(8) now supports random ranges with steps by justsomehnguy on Monday May 08, 2023 @02:30PM (#35865275)
Ah, yes, lets add exclusive flock support to all binaries in the existence, just in case.

You are confusing running a process with running a task from scheduler.

Re:OpenBSD cron(8) now supports random ranges with steps by pengaru on Monday May 08, 2023 @02:35PM (#35865347)
> Ah, yes, lets add exclusive flock support to all binaries in the existence, just in case.

You are aware that flock(1) is a thing, right? And that a defacto core tenet of UNIX is composability of disparate programs that do one thing well?

Re:OpenBSD cron(8) now supports random ranges with steps by justsomehnguy on Monday May 08, 2023 @02:46PM (#35865493)
> You are aware that flock(1) is a thing, right?

No. Maybe I heard and even knew what it is, but I never needed it.

You know why?

My task scheduler supports running only one instance of the task so I don't need to reinvent the wheel every time I need something to run on schedule.

Just 'somebinary args args args', 'run only one instance' and I'm done.

> flock - manage locks from shell scripts

Well, yep. Reinventing the wheel each other time.

Thanks, I have some more important things (like browsing HN) than writing shitty shell scripts.

Re:OpenBSD cron(8) now supports random ranges with steps by pengaru on Monday May 08, 2023 @02:52PM (#35865555)
> No. Maybe I heard and even knew what it is, but I never needed it.

...

> Thanks, I have some more important things (like browsing HN) than writing shitty shell scripts.

Probably a good idea, before you dig that hole of incompetence any deeper.

We're talking about crond here, which is already running the scheduled commands via sh, it's inherently involving the shell. Welcome to *NIX.

Re:OpenBSD cron(8) now supports random ranges with steps by justsomehnguy on Monday May 08, 2023 @04:29PM (#35866647)
> efore you dig that hole of incompetence any deeper.

"Hur-dur! Look at me! Me mighty UNIX wizard! Bow to me!"

> running the scheduled commands via sh, it's inherently involving the shell. Welcome to *NIX.

Thanks, while you are running shell commands I'm running systems. I'm not interested in writing shell scripts for things what were solved decades ago.

Re:OpenBSD cron(8) now supports random ranges with steps by gsich on Monday May 08, 2023 @05:02PM (#35867020)
Better look into a mirror ...

Using cron (or systemd) to ensure only 1 instance is running is a valid approach.

Re:OpenBSD cron(8) now supports random ranges with steps by trasz4 on Monday May 08, 2023 @04:36PM (#35866726)
>Well, yep. Reinventing the wheel each other time.

Erm, no - flock(1) is a UNIX tool, a component if you will. It's the exact opposite of reinventing the wheel.

Not understanding the operating system you're using is fine, but it's good to at least know what you don't know.

Re:OpenBSD cron(8) now supports random ranges with steps by justsomehnguy on Tuesday May 09, 2023 @01:30AM (#35870520)
> It's the exact opposite of reinventing the wheel.

If I need to write a wrapper script each time I need to run a task on a timer - then it is the proverbial reinventing the wheel. It doesn't matter if you call it a tool, utility or a component. Especially if this was solved decades ago.

> Not understanding the operating system you're using is fine

Ah, another mighty UNIX wizard here.

Re:OpenBSD cron(8) now supports random ranges with steps by trasz4 on Tuesday May 09, 2023 @02:28AM (#35870829)
>If I need to write a wrapper script

And there's your problem - you don't realize "writing a wrapper script" is actually simpler than messing with config files.

Re:OpenBSD cron(8) now supports random ranges with steps by justsomehnguy on Tuesday May 09, 2023 @10:24AM (#35874780)
The 'problem' here is you, serving the machine. I prefer the machine to serve me.
Re:OpenBSD cron(8) now supports random ranges with steps by winrid on Tuesday May 09, 2023 @02:04PM (#35878150)
Using utilities included with your OS is not the machine serving you?
Re:OpenBSD cron(8) now supports random ranges with steps by justsomehnguy on Tuesday May 09, 2023 @03:45PM (#35879463)
Using obsolete utilities for the sake of 'doing the right UNIX way' instead of just ticking a checkbox/adding one line in the task configuration?

Come on, I would repeat it again - it was solved for decades. Why do you need to do the things like it's 1976? Why do you insist everyone else should do that way too and abandon the fruits of the digital age?

Re:OpenBSD cron(8) now supports random ranges with steps by winrid on Wednesday May 10, 2023 @11:59AM (#35889257)
Why would you use something other than cron for many types of tasks? Not everyone needs a distributed system to run a script periodically, they want to actually get things done. :)
Re:OpenBSD cron(8) now supports random ranges with steps by ori_b on Wednesday May 10, 2023 @04:02PM (#35892700)
> Why do you need to do the things like it's 1976?

It was solved decades ago: in 1976. I don't understand why you feel like it wasn't.

Re:OpenBSD cron(8) now supports random ranges with steps by ori_b on Wednesday May 10, 2023 @04:01PM (#35892684)
Why is using the composable OS feature reinventing the wheel?
Re:OpenBSD cron(8) now supports random ranges with steps by joosters on Monday May 08, 2023 @03:34PM (#35866023)
a defacto core tenet of UNIX is composability of disparate programs that do one thing well?

cron goes completely against that principle - after all, you can schedule jobs with the 'at' command, and to make a repeating task, you just make it exec 'at' again each time it is called. cron is for the lazy, no real UNIX hacker would dream of using such an extravagant single-use program. /s

Re:OpenBSD cron(8) now supports random ranges with steps by progmetaldev on Monday May 08, 2023 @04:02PM (#35866338)
You are of course correct, but at the same time, you might (or probably not) be surprised at the number of "system administrators" that are thrown into the job without really having the capability to expand too far on their knowledge. Having the option in cron may help those administrators that specifically search Google for cron usage, and never come across flock.

EDIT: In addition, the Task Scheduler in Windows has this type of option, so it may help those sys admins coming from that environment, leveraging their existing knowledge

Re:OpenBSD cron(8) now supports random ranges with steps by mlyle on Monday May 08, 2023 @04:44PM (#35866833)
If your job is a real script: sure, handle locking in it.

If it's a single command or pipeline... adding the layer of indirection to have a script that runs flock is more opaque. Might as well put it in cron and trust cron to only run it once.

Re:OpenBSD cron(8) now supports random ranges with steps by agapon on Tuesday May 09, 2023 @03:01AM (#35871045)
You don't have to create a script, running a command under flock is still a one-liner in crontab.
Re:OpenBSD cron(8) now supports random ranges with steps by mlyle on Tuesday May 09, 2023 @03:12AM (#35871107)
But it's unnecessary when you can do the same thing in 2 characters.

I like flock(1) and have known how to use it for 15 years. But there's sharp edges.

- It's not standardized. In particular, this means the OpenBSD base system doesn't even include it. It's not like the underlying flock(2) is very well behaved or consistent.

- You need to ask for nonblocking behavior.

- If your command or script can ever result in a daemon launching, it may be holding the lock even though the part of your action that is supposed to be protected by the lock (the script/immediate subprocess) has ceased. so e.g. 'flock -n /tmp/relaunch-apache /etc/init.d/apache2 restart' could be a really bad idea. -u can fix this... in some cases.

Re:OpenBSD cron(8) now supports random ranges with steps by aflag on Monday May 08, 2023 @07:12PM (#35868147)
Even though a process can be run concurrently, it doesn’t mean you necessarily want to. Besides that, your cron itself may be something like “do-something | grep foo > /root/bar”. You obviously don’t want to run that concurrently. You could create a script, but that’s more cumbersome.
Re:OpenBSD cron(8) now supports random ranges with steps by mekster on Monday May 08, 2023 @06:30PM (#35867786)
An external program but there's run-one program in Ubuntu repo.