cron

cron

Manage cron on Norns via Maiden

When initialized, this mod creates a crontab file at data/cron/crontab and loads it as the file for the we user. This starter crontab file contains a recursive cron job that reloads itself each minute, so user edits will get picked up by the system automatically.

If you want it to reload faster, you can do so in the mod menu.

For more about what cron is and how to structure a crontab file, Wikipedia has a decent overview with some examples. If you’ve ever run a command using os.execute() in Maiden, that’s the sort of thing that could be scheduled here.

Be aware that there may be some funkiness with time, especially when you don’t have a network connection. Stuff may run at unexpected times, so don’t rely on this for super-precise tasks.

NOTE: check your time zone! After setting it with sudo raspi-config, you may still need to restart in order for cron to pick up the change.

Example cron jobs

# back up norns at 4am every day
0 4 * * * rsync -avzx /home/we/dust user@server:/path/to/backup/

# save list of installed engines at midnight
@daily find ~/dust -name Engine_*.sc -type f -printf '%f\n' | sort > ~/data/engines.txt

# current weather at my location, every 5 minutes
/5 * * * * curl -s wttr.in/?format=Current%20weather%20in%20%l%20is%20%C%20and%20temperature%20wind%20speed%20is%20%w | espeak -k20 -s 120 -m -w ~/dust/audio/weather.wav

# grab freesound.org random sound of the day
15 4 * * * curl https://freesound.org$(curl -s https://freesound.org | grep mp3_file | head -n 1 | cut -d' ' -f11 | cut -d'"' -f2) -o ~/dust/audio/freesound.ogg && ffmpeg -n -i ~/dust/audio/freesound.ogg ~/dust/audio/freesound.wav && rm ~/dust/audio/freesound.ogg

Requirements

Norns running 210927 or later

Download

Install

In the maiden REPL:

;install https://github.com/stvnrlly/cron.git

As a mod, you’ll then need to do some extra stuff to enable it :

to enable a mod go to SYSTEM > MODS to see the list of installed mods. mods which are loaded will have a small dot to the left of their name. use E2 to selected an item in the list and then use E3 to enable or disable as appropriate. unloaded mods will show a + to the right their name to indicate that they will be enabled (and thus loaded) on restart. loaded mods will show a - to the right of their name indicating they will be disabled on restart.

14 Likes

I don’t understand, is it a development tool? pardon my ignorance, please.

edit: ah, I think I understand better now after searching. It gives norns the capability of “keeping time”… and it’s a scheduler and allows for batch operations? :exploding_head:

3 Likes

Thanks for the question; your understanding is correct. It’s a way to schedule things to happen in the background, using a utility that’s built-in to Unix systems but requires some command-line work to set up and manage. I’ll add a little about cron to the top post and include some example jobs.

4 Likes

It is probably worth mentioning that norns/shield devices don’t have a real time clock hardware (RTC). When a norns devices is powered off its sense of the current date and time stops. When it is booted again its clock begins where it last was. If a network connection is available it will reach out to a time service to sync back up with the real world date/time which causes the on board clock to jump.

The short of it is that using cron in this sort of environment will likely result in stuff running at unexpected times.

8 Likes

ok now I ca understand why whern I run pirate radio my clock is totally fucked up, I will try and then see what happen after thx!

The mod menu now includes the current time, to help check if there’s time funkiness on your machine.

I also added a few more example cron jobs in the top post, with some inspiration from pirate radio & Freesound-of-the-day.

5 Likes

could there be a job to automatically alphabetize the favorite norns scripts?

1 Like

Yeah, I think so. It’d probably be a job that runs a Lua script rather than a one-liner, but that script wouldn’t be super complicated.

Sweet, cron¹ is exactly a sensible and standard way to do what Freesound thing does, if not event-based.

I love it when my synth is unix.

¹ or anacron

1 Like

that makes sense, thanks! when I mentioned that idea on the norns study group discord; I think the response was that alphabetizing favorites could pretty easily work as a norns mod script.

I’m assuming cron could interact with just about anything in norns, including mods - which is certainly an interesting thought.

generally speaking, cron is striking me as something which could be used with norns in an art installation to wonderful effect. there’s an automated/scripted aspect, plus it could be interactive or just linked to the time of day. i mean, that seems to be norns in a nutshell anyway… :metal:

1 Like