Hardware & Software
How Pianobar Teaches You about Config Files and Scheduling Jobs
October 16, 2015
Guest Author
Small projects provide the best learning experiences. With Linux operating systems, there are no shortage of these challenges. Setting up and working with Pianobar, the desktop application for Pandora Internet radio, teaches novice Linux users about configuration files and scheduling tasks. File management and task automation are two vital aspects of surviving and thriving in a Linux environment.
Pianobar on the Command Line
Pianobar is a simple lightweight desktop client accessible through the command line. The application enables users to play and manage radio stations from a registered Pandora account, customize keybindings and text output, use remote control and export event commands, and a variety of other actions to customize stations, learn about artists, and why Pandora chooses those songs.
The installation proves simple enough. Pianobar is compatible with most Linux distributions, Mac OS X, and BSD. Therefore the software package is available in official repositories for quick installation. For Arch Linux, you need to run pacman -S pianobar from the command line. There’s nothing complicated to it. However, if circumstance requires you to build and compile the package from source, refer this video.
Create and Customize the Configuration File
Pianobar does not require a personal configuration file to work since it pulls your personalized stations from the registered Pandora account. Although you don’t need it, creating the configuration file proves valuable.
The Arch Linux Wiki provides an outlined breakdown of Pianobar configuration.
First you must create a new directory with: mkdir ~/.config/pianobar
Then change into the new directory: cd .config/pianobar
Next create the configuration file: touch (nano or text editor of preference) config
In this file you should at least include the basic information of:
- Email = username@email.com
- Password = YourPassword
- audio_quality = {high, medium, low}
- autostart_station = stationid
The last line is of course option, but it’s a nice feature to automate the startup process. Find the stationid by selecting the “i” key when playing a station. When writing the lines, ensure that there remains a single space between the key, equals sign, and value (key = value).
Pianobar functions with preset one character keybindings for a number of actions. The actions allow you to favorite and dislike songs, delete stations, create new stations, ask for song explanations and why Pandora chose it. You have the option of customizing the keybindings in the configuration file.
Lessons Learned
For non Linux and other users not familiar with file management from the command line, this task teaches them to:
- Become familiar with managing files from the command line in a text only environment.
- Move in and out of directories with cd (change directory)
- Create directories with mkdir
- Create and customize a configuration file
Scheduling Pianobar Tasks with Cron
The cron daemon and command schedules jobs to run repeatedly at a specified interval (daily, monthly, hourly, etc.). The cron daemon loads when the system boots and relies on these files:
- /var/spool/cron/crontabs/*
- /etc/crontab
- /etc/cron.d/*
Within specific crontab files you enter comments, variables, specify the shell to run jobs in. Cron runs jobs in the /bin/bash shell by default. The crontab command manages the crontab jobs and files with these options:
- crontab -e: edits the crontab file
- crontab -l: lists scheduled jobs
- contrab -r: removes crontab file and all jobs in the file.
- crontab -cmd -u username: specify a user to manage crontab files and jobs.
The Challenge: Schedule Pianobar to Play in the Background with Cron
Check out the Gentoo cron guide to learn more about the utility and see if you can complete the challenge.
Once you understand the crontab directory and file setup, the concept of scheduling jobs isn’t too complicated. Cron and the at command both become extremely valuable to savvy Systems Administrators who increase their efficiency by scheduling and automating jobs.
Lessons Learned:
- Scheduling music to play without effort on your part is awesome and incredibly creepy if configured on another user’s system and account.
- Use crontabs on a basic level to understand how to schedule jobs.
For IT professionals developing familiarity and skills with Linux operating systems, this small challenge and similar ones introduce and immerse them in the command line. Individuals seeking a Linux+ certification should understand that file management and task automation proves essential as a Linux system administrator.
Pianobar offers remote control options to start and run the application from other host machines and Android devices. We’ll save the more advanced topic for a later date.