I want to record a stream whenever it is live automatically, so I thought of setting a cronjob that runs youtube-dl every 15 minutes to that url.
But once it is recording, how do I prevent the system from starting another recording 15 minutes later simultaneously?
You can use flock for this. flock is a little command line tool to manage locks. It works by wrapping a lock around the execution of a command and stores the state of the lock in a lock file.
You probably want to create a cron job based on a command like the following:
flock by default creates an exclusive lock (meaning only one command referencing a specific lockfile will run) and the
-n
flag causes subsequent jobs to fail until finished (rather the default which is to wait, would could leave you with lots of jobs backed up waiting to run)