Schedule Ecasound with Cron for Radio Playout

Ecasound can be reliably scheduled via cron jobs to automate both playout and recording for a radio station. Because Ecasound is a lightweight, command-line multi-track audio processor, it integrates cleanly with standard Linux automation tools without the overhead of a graphical interface. This article explains how to configure shell scripts, manage audio server connections, and set up crontab entries to schedule automated broadcasts and scheduled aircheck recordings.

Why Use Ecasound and Cron?

Ecasound is designed for low-latency recording, playback, and routing directly from the terminal. When paired with cron, the standard Linux task scheduler, it serves as a minimalist, headless radio automation engine. This approach avoids the resource consumption and instability that can occur with complex graphical radio playout software, making it ideal for dedicated broadcast appliances or remote transmitter sites.

Preparing the Audio Environment for Cron

Cron executes jobs in a restricted, non-interactive shell with minimal environment variables. To ensure Ecasound can communicate with the system's sound architecture (such as ALSA, JACK, or PipeWire), these variables must be defined inside your scripts:

Automating Scheduled Playout

To play pre-recorded shows, station IDs, or syndicated content, create a shell script that wraps the Ecasound command.

Create a script named /usr/local/bin/play_show.sh:

#!/bin/bash
export XDG_RUNTIME_DIR="/run/user/1000"

# Path to audio file passed as the first argument
AUDIO_FILE="$1"

# Play audio via ALSA or JACK
ecasound -i:"$AUDIO_FILE" -o:alsa,default

Make the script executable:

chmod +x /usr/local/bin/play_show.sh

Next, schedule the show in your user crontab using crontab -e:

# Play the morning show every weekday at 06:00
0 6 * * 1-5 /usr/local/bin/play_show.sh /srv/audio/morning_show.wav >> /var/log/ecasound_playout.log 2>&1

Automating Scheduled Recording (Airchecks and Logging)

Legal broadcast logs or rebroadcast recordings can be captured by setting a fixed duration with Ecasound's -t option, which dictates the running time in seconds.

Create a script named /usr/local/bin/record_show.sh:

#!/bin/bash
OUTPUT_DIR="/srv/recordings"
TIMESTAMP=$(date +"%Y%m%d_%H%M")
FILENAME="${OUTPUT_DIR}/aircheck_${TIMESTAMP}.wav"
DURATION="$1" # Duration in seconds

# Record from default input device for specified duration
ecasound -i:alsa,default -o:"$FILENAME" -t:"$DURATION"

Make the script executable:

chmod +x /usr/local/bin/record_show.sh

To schedule a one-hour recording (3600 seconds) every Sunday evening at 20:00:

0 20 * * 0 /usr/local/bin/record_show.sh 3600 >> /var/log/ecasound_record.log 2>&1

Managing Overlaps and Ensuring Reliability

Automating audio tasks via cron introduces potential edge cases that should be handled directly in your scripts: