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:
- ALSA: Direct hardware access generally requires
specifying the device name (e.g.,
alsa -i default -o hw:0,0) and ensuring the cron user belongs to theaudiogroup. - JACK / PipeWire: You must declare the correct
runtime path and server name, such as
export XDG_RUNTIME_DIR="/run/user/$(id -u)"andexport JACK_DEFAULT_SERVER="default".
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,defaultMake the script executable:
chmod +x /usr/local/bin/play_show.shNext, 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.shTo 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:
- Preventing Process Collisions: Use
flockin your cron entries to ensure a previous playback or recording run finishes before a new one starts:0 12 * * * /usr/bin/flock -n /tmp/playout.lock /usr/local/bin/play_show.sh /srv/audio/midday.wav - Format Flexibility: Ecasound relies on standard
audio libraries to read inputs. It handles uncompressed WAV natively,
while formats like MP3 or Ogg Vorbis require proper codec libraries
installed (such as
lameorlibvorbis). - Detailed Logging: Always redirect standard output
and standard error (
>> /path/to/log 2>&1) in your crontab lines to diagnose missing files or disconnected sound cards.