Introduction
Back in 2010, telephony systems often required a practical solution for delivering music on hold. Professional hardware and software components could be costly or inflexible, but for those comfortable with Linux, simple shell scripts offered an adaptable alternative. The following blog post explores a classic Bash script that continuously feeds a telephone system with MP3 files, ensuring that callers are always greeted with music when they are on hold.
What Does the Script Do?
The script is designed to play all MP3 files found in a configured directory, looping through them endlessly. The typical use case is to provide ‘waiting music’—music on hold—for PBX (Private Branch Exchange) systems. The shell script leverages standard Linux tools, with the MP3 player mpg321
serving as the playback engine.
Configuration
All configuration options are stored in a separate file (default: /usr/local/etc/telko-musik.sh.conf
). The most important setting is mp3dir
, which specifies the directory containing MP3 files:
mp3dir=/usr/local/mp3
How the Script Works
- Environment Setup:
The script checks for its configuration file and sources it. It then verifies if themp3dir
exists. - Process Management:
Several helper functions are defined for logging, error handling, debugging, and cleanup. - Argument Handling:
It accepts arguments for verbosity, a running-check mode, and help. - File Copying:
The script copies all MP3s into a temporary directory, reducing the risk of issues if files are changed during playback. - Main Playback Loop:
It iterates over all MP3 files in the temporary location, playing them one by one withmpg321
. It sleeps briefly between tracks and repeats indefinitely. - Dynamic Updates:
Because the script periodically re-reads the contents of the specified directory (after each loop iteration), new MP3 files will be detected without needing to restart the script.
How to Use the Script
- Install mpg321:
Ensure the MP3 playermpg321
is installed on your Linux system. - Set up MP3 Directory:
Place all hold music MP3 files in the directory specified bymp3dir
. - Configure the Script:
Edit/usr/local/etc/telko-musik.sh.conf
to pointmp3dir
to the correct folder. - Run the Script:
Execute the script with./telko-musik.sh
(preferably as a dedicated service or background process). - Integration with PBX:
Make sure your telephone system’s hardware is set to accept the audio output generated by the script.
Advantages of This Approach
- Simplicity: Only a few dependencies and easy to configure.
- Automatic Updates: New music files are picked up without a restart.
- Open Source: Distributed under GPL v3, it’s free to use and modify.
Conclusion
This Bash script, typical of early 2010s Linux telephony solutions, offers a robust, simple way to manage hold music for small business telephone systems using free and open-source utilities. It demonstrates how Linux can bridge the gap between legacy PBX hardware and modern audio file formats.